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
42
gaia/apps/clock/js/async_queue.js
Executable file
42
gaia/apps/clock/js/async_queue.js
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
define(function(require) {
|
||||
|
||||
/**
|
||||
* A serial queue of functions. Call `.push()` to add a function to
|
||||
* the task; when each function completes (as a result of calling
|
||||
* 'done()'), the next item in the queue will be executed.
|
||||
*/
|
||||
function AsyncQueue() {
|
||||
this.queue = [];
|
||||
this.current = null;
|
||||
}
|
||||
|
||||
AsyncQueue.prototype = {
|
||||
/**
|
||||
* Add a function to the execution queue. It should accept one
|
||||
* argument, a 'done' callback.
|
||||
*/
|
||||
push: function(fn) {
|
||||
if (!this.current) {
|
||||
this._startTask(fn);
|
||||
} else {
|
||||
this.queue.push(fn);
|
||||
}
|
||||
},
|
||||
|
||||
_startTask: function(fn) {
|
||||
this.current = fn;
|
||||
fn(this._nextTask.bind(this));
|
||||
},
|
||||
|
||||
_nextTask: function() {
|
||||
this.current = null;
|
||||
if (this.queue.length) {
|
||||
this._startTask(this.queue.shift());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return AsyncQueue;
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue