VulpesOS/gaia/apps/system/js/gaia_scheduler.js
OverSu b38dea0597 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.
2026-09-30 23:13:03 +02:00

55 lines
1.4 KiB
JavaScript

/* global BaseModule */
'use strict';
(function() {
var GaiaScheduler = function() {
};
GaiaScheduler.SERVICES = [
'schedule'
];
BaseModule.create(GaiaScheduler, {
name: 'GaiaScheduler',
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();
}
});
}
});
}());