# Atomics.sleep to sleep in worker threads without allocation or COOP+COEP

**URL:** <https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693>\
**Category:** 💡 Ideas\
**Created:** [November 23, 2026, 7:19pm UTC](https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693 "2026-11-23T19:19:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndren](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ndren/32/2770_2.png) [@ndren](https://es.discourse.group/u/ndren)\
**Post date:** [November 23, 2026, 7:19pm UTC](https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693/1 "2026-11-23T19:19:42Z")

</div>

Currently you need to allocate a dummy SharedArrayBuffer (or if you can't turn off COOP/COEP you need to use WebAssembly.Memory) just to invoke sleepSync in a worker thread:  
`const sab = new WebAssembly.Memory({ initial: 1, maximum: 1, shared: true }).buffer; const view = new Int32Array(sab);`  
`Atomics.wait(view, 0, 0, ms);`  
This is a rather cursed way to implement sleep, a very important primitive in lots of programming languages you might want to cross-compile to wasm (and FFI into a JS worker thread to sleep)  
Historically, on the Atomics.pause proposal you could add in an n value to increase the sleep time but this was then ignored by browsers and so dropped to preserve cross-compatibility. Perhaps here it'd be more useful as you can restrict it to only work outside the main thread? Syntax would be `Atomics.sleep(ms)`.

---

<div class="post-metadata">

**Author:** ![ndren](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ndren/32/2770_2.png) [@ndren](https://es.discourse.group/u/ndren)\
**Post date:** [November 23, 2026, 7:22pm UTC](https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693/2 "2026-11-23T19:22:35Z")

</div>

I am also aware you can lower this to 4 bytes by getting the SAB constructor from WebAssembly.Memory, but again a cursed workaround for what should be a fairly simple primitive?

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 23, 2026, 7:35pm UTC](https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693/3 "2026-11-23T19:35:34Z")

</div>

For compiling to wasm one option would be to use [Introducing the WebAssembly JavaScript Promise Integration API · V8](https://v8.dev/blog/jspi) so that the wasm side "blocks" (suspends) but it does an async setTimeout wait on the JS side

---

<div class="post-metadata">

**Author:** ![ndren](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ndren/32/2770_2.png) [@ndren](https://es.discourse.group/u/ndren)\
**Post date:** [November 23, 2026, 7:41pm UTC](https://es.discourse.group/t/atomics-sleep-to-sleep-in-worker-threads-without-allocation-or-coop-coep/2693/4 "2026-11-23T19:41:33Z")

</div>

Yes JSPI is fine if the toolchain you're using to target wasm supports that but that requires the bundler to cooperate
