Fix platform update logic

This commit is contained in:
Girish Ramakrishnan
2019-09-24 20:29:01 -07:00
parent 00fd9e5b7f
commit 85c13cae58
9 changed files with 80 additions and 50 deletions

View File

@@ -1,7 +1,6 @@
'use strict';
exports = module.exports = {
initializeSync: initializeSync,
scheduleTask: scheduleTask
};
@@ -16,6 +15,7 @@ let assert = require('assert'),
let gActiveTasks = { }; // indexed by app id
let gPendingTasks = [ ];
let gInitialized = false;
const TASK_CONCURRENCY = 3;
const NOOP_CALLBACK = function (error) { if (error) debug(error); };
@@ -28,12 +28,19 @@ function waitText(lockOperation) {
return ''; // cannot happen
}
function initializeSync() {
gInitialized = true;
locker.on('unlocked', startNextTask);
}
// callback is called when task is finished
function scheduleTask(appId, taskId, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof taskId, 'string');
assert.strictEqual(typeof callback, 'function');
if (!gInitialized) initializeSync();
if (appId in gActiveTasks) {
return callback(new Error(`Task for %s is already active: ${appId}`));
}
@@ -77,6 +84,3 @@ function startNextTask() {
scheduleTask(t.appId, t.taskId, t.callback);
}
function initializeSync() {
locker.on('unlocked', startNextTask);
}