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
55
gaia/apps/system/js/scheduler.js
Executable file
55
gaia/apps/system/js/scheduler.js
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
/* global BaseModule */
|
||||
'use strict';
|
||||
|
||||
(function() {
|
||||
var Scheduler = function() {
|
||||
};
|
||||
Scheduler.SERVICES = [
|
||||
'schedule'
|
||||
];
|
||||
BaseModule.create(Scheduler, {
|
||||
name: 'Scheduler',
|
||||
DEBUG: false,
|
||||
_start: function() {
|
||||
this._queue = [];
|
||||
this.hold(); // Hold on start until the parent tells us to release.
|
||||
},
|
||||
hold: function() {
|
||||
this._busyState = true;
|
||||
},
|
||||
release: function() {
|
||||
if (this._busyState) {
|
||||
document.body.setAttribute('ready-state', 'visuallyLoaded');
|
||||
window.performance.mark('visuallyLoaded');
|
||||
}
|
||||
this._busyState = false;
|
||||
if (this._queue.length) {
|
||||
this.execute();
|
||||
}
|
||||
},
|
||||
execute: function() {
|
||||
var length = this._queue.length;
|
||||
this.debug('process operations in the schedule pool: ' + length);
|
||||
this._queue.forEach(function(operation) {
|
||||
operation.request();
|
||||
operation.resolve();
|
||||
});
|
||||
this._queue = [];
|
||||
},
|
||||
schedule: function(request) {
|
||||
return new Promise((resolve) => {
|
||||
if (this._busyState) {
|
||||
this.debug('busy loading, put the operation in the pool.');
|
||||
this._queue.push({
|
||||
resolve: resolve,
|
||||
request: request
|
||||
});
|
||||
} else {
|
||||
this.debug('not blocking, execute right away');
|
||||
request();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
||||
Loading…
Reference in a new issue