4 ms·
One thing that is not covered in the post is how should we clean up those goroutines that are blocked on channels. I'm not familiar with internal workings of co
by alco 13y ago
One thing that is not covered in the post is how should we clean up those goroutines that are blocked on channels. I'm not familiar with internal workings of core.async, so I'm looking at it from Go's point of view.
Imagine that in the search example, inside the `google` function, we want to read from 100 channels. And each call to `fastest` is supplied with 100 arguments. If on average we get 100 results back in the allotted time, 900 goroutines will be left in a blocked state waiting for someone to read from their respective channel.
I'm guessing those goroutines are cheap and are implemented as some sort of state machine that maps to callbacks. But all those blocked goroutines should still incur runtime cost. Will the GC kick in collect those?
If this issue is really there (i.e. if I'm not mistaken), imagine what will become of your one-page-web-app after you click on that Search button a dozen of times.
- swannodette 13y agogo blocks are cheap to construct and yes they will be GCed. You can trivially debounce the click channel.
- alco 13y agoThanks for the info! I'm willing to get my hands dirty and see how it's all implemented there. Just for the record, in Go, if you leave a goroutine blocked on a channel, the channel and the goroutine will remain on the heap unless you read everything from the channel (normal way) or close it (and get a runtime panic).