Conc: Better Structured Concurrency for Go
1–10 of 162 posts
Re: Conc: Better Structured Concurrency for Go
#2Re: Conc: Better Structured Concurrency for Go
#3Re: Conc: Better Structured Concurrency for Go
#4 p.WithCollectErrored() configures result pools to only collect results that did not errorRe: Conc: Better Structured Concurrency for Go
#5 func process(stream chan int) {
var wg sync.WaitGroup
for i := 0; i
And func process(stream chan int) {
p := pool.New().WithMaxGoroutines(10)
for elem := range stream {
elem := elem
p.Go(func() {
handle(elem)
})
}
p.Wait()
}
Do slightly different things. The first one has 10 independent, long-lived, go-routines that are all consuming from a single channel. The second one has the current thread read from the channel and dynamically spawn go-routines. They have the same effect, but different performance characteristics.Re: Conc: Better Structured Concurrency for Go
#6Just took a glance but it seems like this is exactly the kind of project I saw coming out of generics going live. I was really surprised to see how subtly hard go concurrency was to do right when initially learning it. Something like this that formalizes patterns and keeps you from leaking goroutines / deadlocking without fuss is great.
When they announced generics the first thing I did with it was rewrite my common slice parallel algorithm and my limited concurrency pool. It is an obvious area needing improvement for common use cases.
Re: Conc: Better Structured Concurrency for Go
#7> A frequent problem with goroutines in long-running applications is handling panics. A goroutine spawned without a panic handler will crash the whole process on panic. This is usually undesirable.
In go land, this seems desirable. Recoverable errors should be propagated as return values, not as panics.
Re: Conc: Better Structured Concurrency for Go
#8I think one of the examples they give is a bit misleading. This func process(stream chan int) { var wg sync.WaitGroup for i := 0; i And func process(stream chan int) { p := pool.New().WithMaxGoroutines(10) for elem := range stream { elem := elem p.Go(func() { handle(elem) }) } p.Wait() } Do slightly different things. The first one has 10 independent, long-lived, go-routines that are all consuming from a single channe…
Which still isn't exactly equivalent, there's still an additional channel read due to the `for elem := range stream {}` loop, and likely an allocation due to the closure.
Re: Conc: Better Structured Concurrency for Go
#9Re: Conc: Better Structured Concurrency for Go
#10Is it just me or are the names and descriptions really confusing? i.e. p.WithCollectErrored() configures result pools to only collect results that did not error
If you click through to the actual api doc it makes a lot more sense: " WithCollectErrored configures the pool to still collect the result of a task even if the task returned an error. By default, the result of tasks that errored are ignored and only the error is collected."