Promise wrapper not using done channel
FrankReh opened this issue · comments
Looks like the 'done' variable is created and closed by the Promised method but never waited on. A typo or something subtle going on that I didn't recognize when looking through this code?
I was actually looking for an example of how to marry the idea of the promise's asynchronous calls to onFulfilled and onRejected callbacks with the go-wasm requirement to call Release on the two Callbacks that would have been created, and this wrapper does show that. Each callback is a closure that will release both callbacks once invoked. Nice.
And naively, I was wondering how to slip a call to 'go' in such code to indicate that the callbacks would be done on a separate goroutine but of course it doesn't call go, the javascript Promise will get one of the callbacks invoked on a subsequent trip through the javascript event loop. It was helpful to see this code and have to figure out how to go runtime would handle it without another goroutine being created. A javascript promise is an interesting way to write an asynchronous function without calling go.