Last active
September 26, 2015 17:30
-
-
Save cameron-martin/3767d7a4bd7c01cd1fbe to your computer and use it in GitHub Desktop.
Promise Pipelining
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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