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
Add the following to errgroup.Group (note: I don't really like the names, bikeshedding is welcome):
// GoChan is like Go, but returns a channel that is closed after f has returned.
func (g *Group) GoChan(f func() error) <-chan struct{}
// TryGoChan is like TryGo but, if f was started, it returns a non-nil channel like GoChan.
func (g *Group) TryGoChan(f func() error) <-chan struct{}
The channel returned by these variants is closed after f terminates and, crucially, aftercancel has been called on the context (if necessary).
I just sketched out the idea here (untested! it's just to discuss the potential semantics).
My main usecase for this is in the following (simplified) scenario:
ch:=eg.GoChan(func() error {
// ...
})
eg.Go(func() error {
// do something ...select {
case<-ctx.Done():
returnctx.Err()
case<-ch:
}
// do something else, but only after the first function has completed
})
(this example above is extremely simplified, in reality there are often many more calls, sometimes not even known statically, and with more complex relationships between functions, so manually finding an order becomes unwieldy fast - and especially maintaining that code becomes much harder)
The text was updated successfully, but these errors were encountered:
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
CAFxX
changed the title
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed when f terminates
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed when f terminates
Aug 16, 2024
CAFxX
changed the title
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed when f terminates
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed when f terminates
Aug 16, 2024
CAFxX
changed the title
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed when f terminates
proposal: x/sync/errgroup: add (Try?)Go variants that return channel closed after f terminates
Aug 16, 2024
Proposal Details
Add the following to
errgroup.Group
(note: I don't really like the names, bikeshedding is welcome):The channel returned by these variants is closed after
f
terminates and, crucially, aftercancel
has been called on the context (if necessary).I just sketched out the idea here (untested! it's just to discuss the potential semantics).
My main usecase for this is in the following (simplified) scenario:
(this example above is extremely simplified, in reality there are often many more calls, sometimes not even known statically, and with more complex relationships between functions, so manually finding an order becomes unwieldy fast - and especially maintaining that code becomes much harder)
The text was updated successfully, but these errors were encountered: