summaryrefslogtreecommitdiff
path: root/cli/rt/11_timers.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-09-22 19:33:29 +0200
committerGitHub <noreply@github.com>2020-09-22 19:33:29 +0200
commitdd1cd4d95237359acd822143265d7d2365bf928c (patch)
tree33ea942ad0630d6efcfcdbeac1f9d45cb48d4599 /cli/rt/11_timers.js
parenta43984c9cfcea852ca18e1c575f9acdb8f023a5a (diff)
fix: clearing timers race condition (#7617)
Diffstat (limited to 'cli/rt/11_timers.js')
-rw-r--r--cli/rt/11_timers.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/cli/rt/11_timers.js b/cli/rt/11_timers.js
index ee909dbd9..8f6a7e049 100644
--- a/cli/rt/11_timers.js
+++ b/cli/rt/11_timers.js
@@ -8,8 +8,12 @@
core.jsonOpSync("op_global_timer_stop");
}
- async function opStartGlobalTimer(timeout) {
- await core.jsonOpAsync("op_global_timer", { timeout });
+ function opStartGlobalTimer(timeout) {
+ return core.jsonOpSync("op_global_timer_start", { timeout });
+ }
+
+ async function opWaitGlobalTimer() {
+ await core.jsonOpAsync("op_global_timer");
}
function opNow() {
@@ -314,7 +318,8 @@
// some timeout/defer is put in place to allow promise resolution.
// Ideally `clearGlobalTimeout` doesn't return until this op is resolved, but
// I'm not if that's possible.
- await opStartGlobalTimer(timeout);
+ opStartGlobalTimer(timeout);
+ await opWaitGlobalTimer();
pendingEvents--;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
prepareReadyTimers();