diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/when/sequence.js | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) |
add node_modules to address #4364
Diffstat (limited to 'node_modules/when/sequence.js')
-rw-r--r-- | node_modules/when/sequence.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/node_modules/when/sequence.js b/node_modules/when/sequence.js new file mode 100644 index 000000000..5f0bc4f85 --- /dev/null +++ b/node_modules/when/sequence.js @@ -0,0 +1,46 @@ +/** @license MIT License (c) copyright 2011-2013 original author or authors */ + +/** + * sequence.js + * + * Run a set of task functions in sequence. All tasks will + * receive the same args. + * + * @author Brian Cavalier + * @author John Hann + */ + +(function(define) { +define(function(require) { + + var when = require('./when'); + var all = when.Promise.all; + var slice = Array.prototype.slice; + + /** + * Run array of tasks in sequence with no overlap + * @param tasks {Array|Promise} array or promiseForArray of task functions + * @param [args] {*} arguments to be passed to all tasks + * @return {Promise} promise for an array containing + * the result of each task in the array position corresponding + * to position of the task in the tasks array + */ + return function sequence(tasks /*, args... */) { + var results = []; + + return all(slice.call(arguments, 1)).then(function(args) { + return when.reduce(tasks, function(results, task) { + return when(task.apply(void 0, args), addResult); + }, results); + }); + + function addResult(result) { + results.push(result); + return results; + } + }; + +}); +})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }); + + |