Created
April 13, 2019 06:38
-
-
Save cwbak/d94c453668a10410f49de76a88645021 to your computer and use it in GitHub Desktop.
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
for start := time.Now(); time.Since(start) < time.Second; { | |
foo(); | |
} |
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
loop: | |
for timeout := time.After(time.Second); ; { | |
select { | |
case <-timeout: | |
fmt.Println("x") | |
break loop | |
default: | |
} | |
foo(); | |
} |
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
for stay, timeout := true, time.After(time.Second); stay; { | |
foo() | |
select { | |
case <-timeout: | |
stay = false | |
default: | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment