Get with timeout cause goroutine leak
liguangsheng opened this issue · 0 comments
liguangsheng commented
If I use the Get method with a 2s timeout, then a goroutine leak will occur from the call to comple after 2s.
package main
import (
"fmt"
"runtime"
"sync"
"time"
"github.com/reugn/async"
)
func main() {
var wg sync.WaitGroup
fmt.Println(runtime.NumGoroutine()) // 101
for i := 0; i < 100; i++ {
promise := async.NewPromise[string]()
go func() {
wg.Add(1)
defer wg.Done()
time.Sleep(time.Second * 4)
promise.Success("OK")
}()
go func() {
wg.Add(1)
defer wg.Done()
fut := promise.Future()
_, _ = fut.Get(time.Second * 2)
time.Sleep(time.Second * 4)
_, _ = fut.Join()
}()
}
wg.Wait()
fmt.Println(runtime.NumGoroutine()) // 101
}