wasm, jsFunc, promises, blocking, sync vs async... quick question

200 views
Skip to first unread message

atd...@gmail.com

unread,
Jul 12, 2025, 11:26:55 AM7/12/25
to golang-nuts
Hello,

Quick question.
A JS function that calls into Go code via a Func wrapper (meaning it was defined in Go wasm code) is not allowed to block.

Reason being that its execution blocks the event loop.

Could that be relaxed so that we can cooperatively yield back to javascript?

I am not sure it makes sense but I think I have a use case: I want a synchronous wrapper around indexedDB which is an async javascript API.

Originally, the idea was to block in wasm until the indexedDB promise resolved and called back into go to unblock the goroutine.
But if I block in wasm, the promise can't resolve because the event loop is also blocked and Promises are async and as such require the event loop.
If the promise can't run it can't unblock the goroutine. If the goroutine can't be unblocked, then the event loop can't either. DEADLOCK! :s

Any idea? Does it make sense?




atd...@gmail.com

unread,
Jul 12, 2025, 12:10:43 PM7/12/25
to golang-nuts
Ok seems to be related to that: Javascript Promise Integration

Christian Stewart

unread,
Jul 24, 2025, 3:49:57 PM7/24/25
to golang-nuts
Hi,


This is a library for IndexedDB in Go which works around a lot of quirks.

Thanks,
Christian
Reply all
Reply to author
Forward
0 new messages