Replies: 2 comments 4 replies
-
I agree that this is a category of use for goroutines that is not currently nicely handled by The I think the biggest design hurdle here is, in order to propagate a panic before calling func processStream(input <-chan int, output chan<- int) {
s := stream.New().WithMaxGoroutines(8)
for elem := range input {
elem := elem
s.Go(func() stream.Callback {
res := fetch(elem)
return func() { output <- res }
})
}
s.Wait()
} While blocked on a read from Another important consideration is, without a cancellation mechanism, groups don't work well for long-running goroutines because we can't propagate a panic until all the spawned goroutines exit. So even if we have a way to propagate a panic, we don't have a way to tell the other goroutines to exit unless we're using something like In general, I think it's an antipattern to "handle" a panic by logging it or whatever, so I don't want to make it super easy to do that by adding something like "WithPanicHandler" (this is still achievable by using I'm not sure this actually brought us closer to a solution, but I'll keep mulling over it 🙂 I'd be curious to see design ideas here. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm new to conc so sorry if I'm jumping in inappropriately, but, is there really a case for long-lived pools? Thread pools are a thing in other languages due to the cost of threads, but a conc pool is not expensive to create (or put another way, if you are creating so many pools that it becomes a problem, your probably have other issues.) The thing I like about conc is that it steers me away from patterns that are more likely to result in headaches than benefits. |
Beta Was this translation helpful? Give feedback.
-
I think there might be a category of use cases where one might want to maintain a long-lived pool where:
Somewhat related: #86 (comment), #89 (comment)
This might be something that's useful to offer separately, since I think all the
conc.WaitGroup
-based mechanisms should definitely not be used for long-lived goroutine pools (most notably because panics get swallowed untilWait()
)Beta Was this translation helpful? Give feedback.
All reactions