Skip to content

Instantly share code, notes, and snippets.

@ankur22
Created May 8, 2020 19:55
Show Gist options
  • Save ankur22/b2c77c3576c09ace9a6706ca0c0390ae to your computer and use it in GitHub Desktop.
Save ankur22/b2c77c3576c09ace9a6706ca0c0390ae to your computer and use it in GitHub Desktop.
Using range over a channel
eg.Go(func() error {
for l := range lines {
select {
case <-ctx.Done():
fmt.Println("Sender: Context closed")
return ctx.Err()
default:
fmt.Printf("Sender: Sending %s to remote database\n", l)
}
}
return nil
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment