From e9ebea66c399dc970a8d7846ddf265a24ef03498 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Fri, 5 Jan 2024 18:58:45 +0000
Subject: [PATCH] ghc-internal: fix threadDelay for wasm in browsers

This commit fixes broken threadDelay for wasm when it runs in
browsers, see added note for detailed explanation.
---
 libraries/ghc-internal/src/GHC/Conc/IO.hs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libraries/ghc-internal/src/GHC/Conc/IO.hs b/libraries/ghc-internal/src/GHC/Conc/IO.hs
index 24d4266477bd..e03decc0b768 100644
--- a/libraries/ghc-internal/src/GHC/Conc/IO.hs
+++ b/libraries/ghc-internal/src/GHC/Conc/IO.hs
@@ -74,6 +74,11 @@ import GHC.Conc.Windows (asyncRead, asyncWrite, asyncDoProc, asyncReadBA,
 import qualified GHC.Event.Thread as Event
 #endif
 
+#if defined(wasm32_HOST_ARCH)
+import qualified GHC.Wasm.Prim.Conc as Wasm
+import qualified GHC.Wasm.Prim.Flag as Wasm
+#endif
+
 ensureIOManagerIsRunning :: IO ()
 #if defined(javascript_HOST_ARCH)
 ensureIOManagerIsRunning = pure ()
@@ -204,6 +209,8 @@ threadDelay time
 #if defined(mingw32_HOST_OS)
   | isWindowsNativeIO = Windows.threadDelay time
   | threaded          = Windows.threadDelay time
+#elif defined(wasm32_HOST_ARCH)
+  | Wasm.isJSFFIUsed  = Wasm.threadDelay time
 #elif !defined(javascript_HOST_ARCH)
   | threaded  = Event.threadDelay time
 #endif
-- 
GitLab