Create a gist now

Instantly share code, notes, and snippets.

// using iojs-v1.5.1 to run the code
/* jshint esnext:true */
/* globals console */
'use strict';
var app = {
pipeline: function(){
var pipeline = {};
// using arguments slice because iojs needs flags for Spreads
pipeline.tasks = Array.prototype.slice.call(arguments);
pipeline.generator = function*(){
for (let k = 0; k < pipeline.tasks.length; k++) {
yield pipeline.tasks[k](pipeline.iterator.next.bind(pipeline.iterator));
}
};
pipeline.iterator = pipeline.generator();
return {
pipeline: pipeline,
start: pipeline.iterator.next.bind(pipeline.iterator)
};
}
};
var tasks = app.pipeline(task1, task2, task3);
tasks.start();
// the tasks
function task1(done){
setImmediate(function(){
console.log('task1 done!');
done();
});
}
function task2(done){
setTimeout(function(){
console.log('task2 done!');
done();
}, 3000);
}
function task3(done){
setImmediate(function(){
console.log('task3 done!');
done();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment