go-promise
go-promise copied to clipboard
Return channel on promise.Resolve
I think it would be great being able to wait for Resolve
method to actually run its callbacks, or at least to have two methods like Resolve
and ResolveAsync
.
I'd expect the following code to print "running callback" but this doesn't happen since promise.Resolve
is using a go routine and this is not clear.
package main
import "github.com/fanliao/go-promise"
import "fmt"
func main() {
p := promise.NewPromise()
p.OnSuccess(func(v interface{}) {
fmt.Println("running callback")
})
p.Resolve(nil)
}
Thank you!
I think that does not happen because the application closes before the goroutine runs. Try to put a time.Sleep(time.Second) after the p.Resolve. It should print OnSuccess.
Btw, that might happen on Nodejs as well. If the application finishes, it does not wait for all promises to execute their callbacks.