From f7622708a1e8fa26668f2fd5566ec9d2b8c4a493 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 2 Nov 2018 10:36:56 +0000 Subject: [PATCH] Use Promise.then(f) instead of setTimeout(f, 0) --- src/ground.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ground.js b/src/ground.js index 61d19df..689ccbc 100644 --- a/src/ground.js +++ b/src/ground.js @@ -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 };