Open
Description
Proposal Details
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, after cancel
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():
return ctx.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)
Metadata
Metadata
Assignees
Type
Projects
Status
Incoming
Milestone
Relationships
Development
No branches or pull requests
Activity
gabyhelp commentedon Aug 16, 2024
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]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[/+][-]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[/+][-]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[/+]