2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('parallel', function (Y, NAME) {
12 * A concurrent parallel processor to help in running several async functions.
18 A concurrent parallel processor to help in running several async functions.
20 var stack = new Y.Parallel();
22 for (var i = 0; i < 15; i++) {
23 Y.io('./api/json/' + i, {
25 success: stack.add(function() {
31 stack.done(function() {
35 @param {Object} o A config object
36 @param {Object} [o.context=Y] The execution context of the callback to done
41 Y.Parallel = function(o) {
42 this.config = o || {};
44 this.context = this.config.context || Y;
49 Y.Parallel.prototype = {
51 * An Array of results from all the callbacks in the stack
58 * The total items in the stack
64 * The number of stacked callbacks executed
70 * Add a callback to the stack
72 * @param {Function} fn The function callback we are waiting for
82 self.results[index] = (fn && fn.apply(self.context, arguments)) ||
83 (arguments.length === 1 ? arguments[0] : Y.Array(arguments));
89 * Test to see if all registered items in the stack have completed, if so call the callback to `done`
94 if (self.finished >= self.total && self.callback) {
95 self.callback.call(self.context, self.results, self.data);
99 * The method to call when all the items in the stack are complete.
101 * @param {Function} callback The callback to execute on complete
102 * @param {Mixed} callback.results The results of all the callbacks in the stack
103 * @param {Mixed} [callback.data] The data given to the `done` method
104 * @param {Mixed} data Mixed data to pass to the success callback
106 done: function (callback, data) {
107 this.callback = callback;
114 }, '3.13.0', {"requires": ["yui-base"]});