Skip to content

Instantly share code, notes, and snippets.

@sillero
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sillero/cc4949b4300647d2dfe5 to your computer and use it in GitHub Desktop.
Save sillero/cc4949b4300647d2dfe5 to your computer and use it in GitHub Desktop.
// 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