/usr/share/javascript/yui3/parallel/parallel.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('parallel', function(Y) {
/**
* A concurrent parallel processor to help in running several async functions.
* @module parallel
* @main parallel
*/
/**
A concurrent parallel processor to help in running several async functions.
var stack = new Y.Parallel();
for (var i = 0; i < 15; i++) {
Y.io('./api/json/' + i, {
on: {
success: stack.add(function() {
})
}
});
}
stack.done(function() {
});
@class Parallel
@param {Object} o A config object
@param {Object} [o.context=Y] The execution context of the callback to done
*/
Y.Parallel = function(o) {
this.config = o || {};
this.results = [];
this.context = this.config.context || Y;
this.total = 0;
this.finished = 0;
};
Y.Parallel.prototype = {
/**
* An Array of results from all the callbacks in the stack
* @property results
* @type Array
*/
results: null,
/**
* The total items in the stack
* @property total
* @type Number
*/
total: null,
/**
* The number of stacked callbacks executed
* @property finished
* @type Number
*/
finished: null,
/**
* Add a callback to the stack
* @method add
* @param {Function} fn The function callback we are waiting for
*/
add: function (fn) {
var self = this;
self.total += 1;
return function () {
self.finished++;
self.results.push(fn && fn.apply(self.context, arguments));
self.test();
};
},
/**
* Test to see if all registered items in the stack have completed, if so call the callback to `done`
* @method test
*/
test: function () {
var self = this;
if (self.finished >= self.total && self.callback) {
self.callback.call(self.context, self.results, self.data);
}
},
/**
* The method to call when all the items in the stack are complete.
* @method done
* @param {Function} callback The callback to execute on complete
* @param {Mixed} callback.results The results of all the callbacks in the stack
* @param {Mixed} [callback.data] The data given to the `done` method
* @param {Mixed} data Mixed data to pass to the success callback
*/
done: function (callback, data) {
this.callback = callback;
this.data = data;
this.test();
}
};
}, '3.5.1' ,{requires:['yui-base']});
|