So i'm implementing a timeout using select / time.After. When i get 4 requests i'm just creating another time.After and replace variable with it, attaching code
----------------------------------------
total_requests := len(
j.id)
out := make([]httpjob_response, 0, total_requests)
timeout := time.After(time.Duration(maxTimeMS) * time.Millisecond)
....
should_run := true
var error_timeout Status = ERR_TIMEOUT
for i := 0; should_run && i < total_requests; i++ {
// here we have special support for case where we already got minResult results
// so we can wait a little more (eg. 5 ms) to try to get the last result, or just finish
if i == minResults {
timeout = time.After(time.Duration(5) * time.Millisecond)
error_timeout = ERR_SKIPPED // if we can't get this request in time, treat it as skipped as we don't need it
}
select {
case v := <-
j.ch:
out = append(out, v)
case <-timeout:
append_missing(error_timeout)
should_run = false
}
}
append_missing(ERR_SKIPPED)
----------------------------------------
Now claude ai is insisting that this time.After (which creates a channel) is getting properly garbage collected. Not sure how, when (as per spec) the channel with pending write should linger indefinitely as long as it isn't read from. Moreover "only the sender should close a channel, and only when it's done sending", during that potential GC this channel will get closed.
If the channel is closed / GC'd with blocking send, how that works. If not, what's some better way of doing that?
"As of Go 1.23, the channel is synchronous (unbuffered, capacity 0)" so if the write occurs before GC, and there is no one to read from the channel, is it still properly collected?