Skip to content

Instantly share code, notes, and snippets.

@cameron-martin
Last active September 26, 2015 17:30
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 cameron-martin/3767d7a4bd7c01cd1fbe to your computer and use it in GitHub Desktop.
Save cameron-martin/3767d7a4bd7c01cd1fbe to your computer and use it in GitHub Desktop.
Promise Pipelining
var pipeline = [
function(title) {
return Promise.resolve(title.replace(/P/g, 'p'));
},
function(title) {
return Promise.resolve(title.replace(/p/g, 't'));
}
];
function combinePipeline(pipeline) {
return function(input) {
return pipeline.reduce(function(promise, pipelineElement) {
return promise.then(pipelineElement);
}, Promise.resolve(input));
}
}
combinePipeline(pipeline)('Promise Pipelining').then(console.log.bind(console));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment