repeatingbeats / invoke

JS flow control micro-library
MIT License
74 stars 2 forks source link

Add methods that operate on arrays of functions #2

Open repeatingbeats opened 12 years ago

repeatingbeats commented 12 years ago

invoke has nice syntax for controlling the flow of individual anonymous functions, but it lacks semantics for operating on arrays of functions.

I'm currently thinking of an API that looks like:


// batch of sequential functions
invoke(batch).sequentially().rescue(function (err) {
  // error handler
}).end(initial, function (results) {
 // success handler
});

// batch of parallel functions
invoke(batch).inParallel().rescue(function (err) {
  // error handler
}).end(initial, function (results) {
  // success handler
});

// complex flow
invoke(function (data, callback) {
  // ...
}).then(sequentialBatch).sequentially().then(function (data, callback) {
 // ...
}).then(parallelBatch).inParallel().rescue(function (err) {
  // error handler
}).end(initial, function (results) {
  // success handler
});
bminer commented 11 years ago

I like this idea, so long as it doesn't blow up the size of the lib. Cool stuff, @repeatingbeats ... keep it up!

IMHO, your lib is cooler than the popular "step" flow control library due to global error handling (i.e. rescue()) function.