This is probably really dense on my part, but how do I handle callbacks in gopherjs?
EG:
window.doSomething(constraints).then(handleSuccess).catch(handleError);
I found examples of deferred calls in the Jquery wrapper. I think I am starting to understand this a bit more.
https://github.com/gopherjs/jquery/blob/master/jquery.go#L828
window.doSomething(constraints).then(handleSuccess).catch(handleError);
Using js package, that would be:
handleSuccess := func(result *js.Object) { ... }
handleError := func(...) { ... }
js.Global.Call("doSomething", constraints).Call("then", handleSuccess).Call("catch", handleError)
You can also see an example here.
Glad to hear it's starting to make sense.
FWIW, if you can refactor your code to write on a channel, that's listened to by a goroutine, that might be better. No point in just rewriting Javascript in Go, _if_ you can avoid it.