Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
61
gaia/shared/js/async_semaphore.js
Executable file
61
gaia/shared/js/async_semaphore.js
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
(function(exports) {
|
||||
var AsyncSemaphore = function as_contructor() {
|
||||
if (!(this instanceof AsyncSemaphore)) {
|
||||
return new AsyncSemaphore();
|
||||
}
|
||||
this._init();
|
||||
};
|
||||
|
||||
// Do not call '_init' and '_execute' directly from outside of AsyncSemaphore
|
||||
AsyncSemaphore.prototype = {
|
||||
_init: function as_init() {
|
||||
// Please don't modify these value directly from outside of AsyncSemaphore
|
||||
this.pendingTasks = [];
|
||||
this.semaphore = 0;
|
||||
},
|
||||
_execute: function as_execute() {
|
||||
var task,
|
||||
context;
|
||||
if (this.semaphore <= 0) {
|
||||
while (this.pendingTasks.length > 0) {
|
||||
task = this.pendingTasks.shift();
|
||||
context = task.context || this;
|
||||
if (task && task.callback && typeof task.callback === 'function') {
|
||||
task.callback.call(context, task.args);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
v: function as_v(num) {
|
||||
if (!num) {
|
||||
num = 1;
|
||||
}
|
||||
this.semaphore += num;
|
||||
},
|
||||
p: function as_p() {
|
||||
this.semaphore -= 1;
|
||||
if (this.semaphore < 0) {
|
||||
this.semaphore = 0;
|
||||
}
|
||||
this._execute();
|
||||
},
|
||||
wait: function as_wait(callback, context, args) {
|
||||
this.pendingTasks.push({
|
||||
callback: callback,
|
||||
context: context,
|
||||
args: args
|
||||
});
|
||||
this._execute();
|
||||
},
|
||||
getValue: function as_getValue() {
|
||||
return this.semaphore;
|
||||
},
|
||||
getTasksLength: function as_getTasksLength() {
|
||||
return this.pendingTasks.length;
|
||||
}
|
||||
};
|
||||
|
||||
exports.AsyncSemaphore = AsyncSemaphore;
|
||||
}(window));
|
||||
Loading…
Reference in a new issue