March 2019
Beginner to intermediate
324 pages
7h 17m
English
GopherJS supports goroutines, so you can use goroutines in your Go code, and GopherJS will take care of the rest.
One important requirement is that goroutines must be used if you need to call some blocking code from an external JavaScript.
For example, consider the following JavaScript code running in the browser:
document.getElementById("myBtn").addEventListener("click", function(){ /*SOME BLOCKING CODE*/});
The preceding code defines a callback function that is expected to execute when a button is clicked.
Here is how this should be handled in Go with the help of GopherJS:
js.Global.Get("document").Call("getElementById", "mybtn").Call("addEventListener","call", func() { go func() { /*SOME BLOCKING CODE*/ }()})
As shown in the ...
Read now
Unlock full access