You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Async executes a function in a goroutine and returns the result in a channel.funcAsync[Aany](ffunc() A) <-chanA {
ch:=make(chanA, 1)
gofunc() {
ch<-f()
}()
returnch
}
Why Async doesn't close the chan?
The text was updated successfully, but these errors were encountered:
Because the chan could be garbage collected automatically when no one cares about it.
the chan have capacity of 1 due to its declaration
ch:=make(chanA, 1)
so the method f must can pass value into this chan without any blocking, and after passing value into the chan, the method cares the chan no more.
// this line of code must can executegofunc() {
ch<-f()
}()
and if anyone listening to the chan outside, they can read it, after they stop reading, then there is no one cares about the chan anymore, in that case, the chan will be garbage collected automatically
Why Async doesn't close the chan?
The text was updated successfully, but these errors were encountered: