summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuite Stegeman <stegeman@gmail.com>2022-12-07 17:34:17 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-09 09:43:38 -0500
commit79b0cec060594edac144d1b4d6c2c809a8d75fab (patch)
tree7bfea253b7e29baec9aaa6ec958db3b5217e83d4
parent1023b432d0befd9675dcfcfb44c548b06b2fae8c (diff)
downloadhaskell-79b0cec060594edac144d1b4d6c2c809a8d75fab.tar.gz
Add support for environments that don't have setImmediate
-rw-r--r--rts/js/thread.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/rts/js/thread.js b/rts/js/thread.js
index b284b3209d..3f179dcbcd 100644
--- a/rts/js/thread.js
+++ b/rts/js/thread.js
@@ -599,7 +599,7 @@ function h$scheduleMainLoop() {
// node.js 0.10.30 has trouble with non-integral delays
h$mainLoopTimeout = setTimeout(h$mainLoop, Math.round(delay));
} else {
- h$mainLoopImmediate = setImmediate(h$mainLoop);
+ h$mainLoopImmediate = h$setImmediate(h$mainLoop);
}
#ifndef GHCJS_BROWSER
}
@@ -617,7 +617,7 @@ function h$clearScheduleMainLoop() {
h$mainLoopTimeout = null;
}
if(h$mainLoopImmediate) {
- clearImmediate(h$mainLoopImmediate);
+ h$clearImmediate(h$mainLoopImmediate);
h$mainLoopImmediate = null;
}
if(h$mainLoopFrame) {
@@ -626,6 +626,15 @@ function h$clearScheduleMainLoop() {
}
}
+var h$setImmediate, h$clearImmediate;
+if(typeof setImmediate !== 'undefined') {
+ h$setImmediate = function(f) { return setImmediate(f); }
+ h$clearImmediate = function(h) { clearImmediate(h); }
+} else {
+ h$setImmediate = function(f) { return setTimeout(f, 0); }
+ h$clearImmediate = function(h) { clearTimeout(h); }
+}
+
function h$startMainLoop() {
TRACE_SCHEDULER("start main loop: " + h$running)
if(h$running) return;
@@ -634,7 +643,7 @@ function h$startMainLoop() {
#endif
if(!h$mainLoopImmediate) {
h$clearScheduleMainLoop();
- h$mainLoopImmediate = setImmediate(h$mainLoop);
+ h$mainLoopImmediate = h$setImmediate(h$mainLoop);
}
#ifndef GHCJS_BROWSER
} else {
@@ -717,7 +726,7 @@ function h$actualMainLoop() {
if(h$animationFrameMainLoop) {
h$mainLoopFrame = requestAnimationFrame(h$mainLoop);
} else {
- h$mainLoopImmediate = setImmediate(h$mainLoop);
+ h$mainLoopImmediate = h$setImmediate(h$mainLoop);
}
return;
}