Skip to content

Instantly share code, notes, and snippets.

@icholy
Created April 6, 2026 13:52
Show Gist options
  • Select an option

  • Save icholy/d478451ca07d20873dfe30ab1947107e to your computer and use it in GitHub Desktop.

Select an option

Save icholy/d478451ca07d20873dfe30ab1947107e to your computer and use it in GitHub Desktop.
package errchan
import (
"golang.org/x/sync/errgroup"
)
func Go[T any](g *errgroup.Group, f func() (T, error)) <-chan T {
ch := make(chan T, 1)
g.Go(func() error {
v, err := f()
ch <- v
return err
})
return ch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment