willconant / flow-js

Javascript Library for Multi-step Asynchronous Logic
MIT License
302 stars 15 forks source link

Modify to work with node's async interface #1

Closed creationix closed 14 years ago

creationix commented 14 years ago

You could modify this slightly to work with node's async interface where the first parameter to the callback is the error message. Then it would work with all the built-in node async functions out of the box.

willconant commented 14 years ago

The special "this" available in each function of the flow will apply the next function in the flow with whatever parameters it is called with, so it should work great with Node's built-in async functions already. Here's an example with some async file IO:

flow.exec(
  function() {
    fs.rename("/tmp/hello", "/tmp/world", this);
  },function(err) {
    if (err) throw err;
    fs.stat("/tmp/world", this);
  },function(err, stats) {
    if (err) throw err;
    sys.puts("stats: " + JSON.stringify(stats));
  }
);

Does that cover your suggestion? Or is there something I'm missing?

creationix commented 14 years ago

Oh, cool. I didn't realize it supported multiple arguments. Brilliant idea by the way.