Last active
January 26, 2017 20:49
-
-
Save blasten/a1d66dc79e0b4d0ce4954dc5eb3431cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_queue = []; | |
_isRunning = false; | |
async _runLoop(task) { | |
let job, queue = this._queue; | |
if (this._isRunning) { | |
// Preempt the current tasks | |
while (job = queue[0]) { | |
queue.shift(); | |
if (job.preemptive) { | |
job.run(); | |
} | |
} | |
} | |
queue.push(task); | |
this._isRunning = true; | |
while (job = queue[0]) { | |
await job.time(); | |
if (job === queue[0]) { | |
queue.shift(); | |
job.run(); | |
} | |
} | |
this._isRunning = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment