Skip to content

Instantly share code, notes, and snippets.

@just1689
Last active April 8, 2018 11:21
Show Gist options
  • Save just1689/e9a027ab22314467fadd3718c3a6cf34 to your computer and use it in GitHub Desktop.
Save just1689/e9a027ab22314467fadd3718c3a6cf34 to your computer and use it in GitHub Desktop.
Timeout channel
timeout := make(chan bool, 1)
go func() {
time.Sleep(1 * time.Second)
timeout <- true
}()
select {
case <-ch:
// a read from ch has occurred
case <-timeout:
// the read from ch has timed out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment