1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('parallel', function (Y, NAME) {
6
* A concurrent parallel processor to help in running several async functions.
12
A concurrent parallel processor to help in running several async functions.
14
var stack = new Y.Parallel();
16
for (var i = 0; i < 15; i++) {
17
Y.io('./api/json/' + i, {
19
success: stack.add(function() {
26
stack.done(function() {
27
Y.log('All IO requests complete!');
31
@param {Object} o A config object
32
@param {Object} [o.context=Y] The execution context of the callback to done
37
Y.Parallel = function(o) {
38
this.config = o || {};
40
this.context = this.config.context || Y;
45
Y.Parallel.prototype = {
47
* An Array of results from all the callbacks in the stack
54
* The total items in the stack
60
* The number of stacked callbacks executed
66
* Add a callback to the stack
68
* @param {Function} fn The function callback we are waiting for
78
self.results[index] = (fn && fn.apply(self.context, arguments)) ||
79
(arguments.length === 1 ? arguments[0] : Y.Array(arguments));
85
* Test to see if all registered items in the stack have completed, if so call the callback to `done`
90
if (self.finished >= self.total && self.callback) {
91
self.callback.call(self.context, self.results, self.data);
95
* The method to call when all the items in the stack are complete.
97
* @param {Function} callback The callback to execute on complete
98
* @param {Mixed} callback.results The results of all the callbacks in the stack
99
* @param {Mixed} [callback.data] The data given to the `done` method
100
* @param {Mixed} data Mixed data to pass to the success callback
102
done: function (callback, data) {
103
this.callback = callback;
110
}, '3.9.1', {"requires": ["yui-base"]});