[Git][ghc/ghc][master] wasm: use scheduler.postTask() for context switch when available
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat May 4 00:53:07 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
43d48b44 by Cheng Shao at 2024-05-03T20:49:30-04:00
wasm: use scheduler.postTask() for context switch when available
This patch makes use of scheduler.postTask() for JSFFI context switch
when it's available. It's a more principled approach than our
MessageChannel based setImmediate() implementation, and it's available
in latest version of Chromium based browsers.
- - - - -
1 changed file:
- utils/jsffi/prelude.js
Changes:
=====================================
utils/jsffi/prelude.js
=====================================
@@ -75,17 +75,21 @@ class SetImmediate {
// The actual setImmediate() to be used. This is a ESM module top
// level binding and doesn't pollute the globalThis namespace.
-let setImmediate;
-if (globalThis.setImmediate) {
- // node.js, bun
- setImmediate = globalThis.setImmediate;
-} else {
+const setImmediate = await (async () => {
+ // https://developer.mozilla.org/en-US/docs/Web/API/Scheduler
+ if (globalThis.scheduler) {
+ return (cb, ...args) => scheduler.postTask(() => cb(...args));
+ }
+ // node, bun, or other scripts might have set this up in the browser
+ if (globalThis.setImmediate) {
+ return globalThis.setImmediate;
+ }
try {
// deno
- setImmediate = (await import("node:timers")).setImmediate;
+ return (await import("node:timers")).setImmediate;
} catch {
// browsers
const sm = new SetImmediate();
- setImmediate = (cb, ...args) => sm.setImmediate(cb, ...args);
+ return (cb, ...args) => sm.setImmediate(cb, ...args);
}
-}
+})();
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/43d48b449a46e805e3baeafbafa62b6cd6f761c9
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/43d48b449a46e805e3baeafbafa62b6cd6f761c9
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240503/efec5c6a/attachment-0001.html>
More information about the ghc-commits
mailing list