pioneer icon indicating copy to clipboard operation
pioneer copied to clipboard

Use fiber for async code

Open totty90 opened this issue 10 years ago • 7 comments

totty90 avatar Feb 13 '15 14:02 totty90

@totty90 mind expanding on this?

samccone avatar Feb 13 '15 14:02 samccone

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.

totty90 avatar Feb 13 '15 15:02 totty90

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.

samccone avatar Feb 13 '15 15:02 samccone

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.

totty90 avatar Feb 13 '15 15:02 totty90

ok @totty90 well if you are interested, we are very open to improvements. Thanks again for bringing this up.

samccone avatar Feb 13 '15 15:02 samccone

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

DominikGuzei avatar Mar 26 '15 13:03 DominikGuzei

Here it is cucumber + fibers + more goodies: https://github.com/hackhat/cucumberry

totty90 avatar Mar 26 '15 14:03 totty90