Last active
April 8, 2018 11:21
-
-
Save just1689/e9a027ab22314467fadd3718c3a6cf34 to your computer and use it in GitHub Desktop.
Timeout channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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