WebAssembly and Goroutines

89 views
Skip to first unread message

W. Michael Petullo

unread,
Nov 17, 2020, 3:37:38 AM11/17/20
to golan...@googlegroups.com
I am having trouble understanding the model for Goroutines within
WebAssembly.

I have a "click" callback with the following form:

errChan := make(chan error, 1)

go func() {
// Call http.PostForm and read response.

if err != nil {
errChan <- err
return
}

// ...
}()

select {
case err := <-errChan:
if err != nil {
// Handle error.
}
case <-time.After(timeout):
// Handle timeout.
}

I had expected http.PostForm to proceed, with the timeout expiring only
if http.PostForm took too long. Yet it seems that http.PostForm blocks
until after the timeout expires. Indeed, the http.PostForm call will not
return until the timer expires, no matter what value I set the timer to.

I setup the above callback (named fork) using:

wasm.AddEventListener(link, "click", js.FuncOf(
func(this js.Value, args []js.Value) interface{} {
return js.FuncOf(fork).Invoke(file)
}))

Does anyone have any recommended reading for performing HTTP requests
from WebAssembly callbacks?

--
Mike

:wq
Reply all
Reply to author
Forward
0 new messages