pioneer
pioneer copied to clipboard
Use fiber for async code
@totty90 mind expanding on this?
By using fibers your code can look like this
var a = makeAsyncRequest().wait();
var b = usingAVarInAnotherAsyncRequest(a).wait();
expect(b).to.be(4);
While with the current way of doing things is kind a pain.
Hi @totty90 , thanks for the great idea. If you are interested in taking a stab at implementing this I would love to take a look and we can evaluate further. You are correct that using the pattern above would remove quite a bit of complexity when writing tests.
Luckily we have a pretty extensive set of unit and integration tests for this library so you can quite easily make a pass on this and be able to see if it is going to be possible.
Thanks again.
You are welcome, I've just moved all my server side services to fibers and 100 lines of code with async just transformed in 10 readable lines. Is like magic. No problems to debug yet. I'm looking into testing frameworks, so I can't promise to make a pull here.
ok @totty90 well if you are interested, we are very open to improvements. Thanks again for bringing this up.
This is pretty much the same problem that I had to solve with integrating Meteor with pioneer.js The short answer is: it is not "really" possible because fibers and promises are orthogonal concepts. But you can introduce a function on the world that wraps a callback inside a fiber.
You can see how I did it with space-pioneer, an acceptance testing framework for Meteor.js based on pioneer.js
Here it is cucumber + fibers + more goodies: https://github.com/hackhat/cucumberry