Package gock (a portmanteau of the go
statement and "block") provides structured concurrency utilities for Go.
ctx, cancel := context.WithCancel(ctx)
things := make(chan Thing)
err := gock.Wait(func() error {
defer close(things)
return Produce(ctx, things)
}, func() error {
defer cancel()
return Consume(things)
})
// Both Produce and Consume are done here, and err is their combined errors.