Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late to the party #21

Closed
stringparser opened this issue Mar 31, 2015 · 3 comments
Closed

Late to the party #21

stringparser opened this issue Mar 31, 2015 · 3 comments

Comments

@stringparser
Copy link

So yeah 😄, anyway, I write this here in case it is something you find interesting.

tl;dr proposal for a non-evented approach for undertaker, maybe not using what I've done but something better.

I have been working for a while now around the same idea of composing async functions using async-done and have come up with a different approach for all of this with no events and one method for series and/or parallel. This is how it looks like:

var tornado = require('tornado').create(); // <- the "registry"

tornado.set(':handle(\\d+)', function(next){
 console.log(this.params.handle);
  setTimeout(next, Math.random()*10); 
});

function handle(next){ 
  setTimeout(next, Math.random()*10); 
}

var series = tornado.stack('1 2', handle, {wait: true}); // => function
var parallel = tornado.stack('3 4', handle); // => function
series(1, 2); parallel(1, 2); 
// passing arguments to each handle works from here or with next(null, 1, 2);

The same logic applies for nesting one "stack" with another as you do with bach. As you see I have added path to regex to the mix (because why not) and string arguments don't have to necessarily be separated by a comma. A space is just fine.

@phated
Copy link
Member

phated commented Mar 31, 2015

Quite late 😉 This seems like a pretty cool use of async-done but it doesn't map nicely to gulp. undertaker doesn't make async-done evented, it just adds task timing events to the execution of the functions, which is quite hard to do without controlling the entire stack. Trust me, I first tried to implement bach on top of async and it was a nightmare, which led me to write now-and-later that allows extension points on the composed function.

@phated phated closed this as completed Mar 31, 2015
@stringparser
Copy link
Author

Haha, thanks. I wanted to write anyway. The idea of a simple way to do async composition is just so pleasant, not only for gulp but in general. The way bach api looks like and composes is just, at least for me, what it should be to compose async functions.

Yeah, control over the arguments that will construct the stack is really important otherwise all is a nightmare. Nesting, and the timing thing (or any other thing like error handling that has to be done between start and end) was the hardest to figure out. For that using async-done for completion of everything but callbacks was the solution. Provide a callback from outside and use it to glue everything. I'll write some pseudocode:

@stringparser
Copy link
Author

Ok

@gulpjs gulpjs locked and limited conversation to collaborators Apr 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants