forked from cujojs/when
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel.js
43 lines (35 loc) · 1.06 KB
/
parallel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** @license MIT License (c) copyright 2011-2013 original author or authors */
/**
* parallel.js
*
* Run a set of task functions in parallel. All tasks will
* receive the same args
*
* @author Brian Cavalier
* @author John Hann
*/
(function(define) {
define(function(require) {
var when, slice;
when = require('./when');
slice = Array.prototype.slice;
/**
* Run array of tasks in parallel
* @param tasks {Array|Promise} array or promiseForArray of task functions
* @param [args] {*} arguments to be passed to all tasks
* @return {Promise} promise for array containing the
* result of each task in the array position corresponding
* to position of the task in the tasks array
*/
return function parallel(tasks /*, args... */) {
return when.all(slice.call(arguments, 1)).then(function(args) {
return when.map(tasks, function(task) {
return task.apply(null, args);
});
});
};
});
})(
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
// Boilerplate for AMD and Node
);