Use Promise.then(f) instead of setTimeout(f, 0)

This commit is contained in:
Tony Garnock-Jones 2018-11-02 10:36:56 +00:00
parent 491b97e3d9
commit f7622708a1
1 changed files with 7 additions and 2 deletions

View File

@ -12,12 +12,17 @@ function Ground(bootProc) {
this.backgroundTaskCount = 0;
}
Ground._resolved = Promise.resolve();
Ground.laterCall = function (thunk) {
Ground._resolved.then(thunk);
};
Ground.prototype.start = function () {
if (!this.stepperId) {
this.stepperId = setTimeout(() => {
this.stepperId = Ground.laterCall(() => {
this.stepperId = null;
this._step();
}, 0);
});
}
return this; // allows chaining start() immediately after construction
};