Closed yougahu closed 1 year ago
commit
+1
It also happens if we collect after resolve
was called:
func Test_Future(t *testing.T) {
completed := make(chan struct{})
fut := mo.NewFuture(func(resolve func(int), reject func(error)) {
resolve(1)
close(completed)
})
<-completed
fut.Collect() // deadlock
}
Hi there
Thanks for inspecting this. @yougahu I gonna merge your commit and create a new release of mo
.
If we call
(*Future[T]).Then
afterFuture[T]
has completed, theThan
-callback will never been called. And if we try toCollect
a completedFuture[T]
, it could cause deadlock.for example:
Futures call next future once they have finished, so if we chain a callback on a finished future, the call chain would be broken.
And here is my commit to fix this commit.