I have two goroutines: the main worker
and a helper
that it spins off for some help. helper
can encounter errors, so I use a channel to communicate errors over from the helper
to the worker
.
func helper(c chan <- error) (){
//do some work
c <- err // send errors/nil on c
}
Here is how helper()
is called:
func worker() error {
//do some work
c := make(chan error, 1)
go helper(c)
err := <- c
return err
}
Questions:
Is the statement
err := <- c
blockingworker
? I don't think so, since the channel is buffered.If it is blocking, how do I make it non-blocking? My requirement is to have
worker
and its caller continue with rest of the work, without waiting for the value to appear on the channel.
Thanks.
c
?