Skip to content

Instantly share code, notes, and snippets.

@cwbak
Created April 13, 2019 06:38
Show Gist options
  • Save cwbak/d94c453668a10410f49de76a88645021 to your computer and use it in GitHub Desktop.
Save cwbak/d94c453668a10410f49de76a88645021 to your computer and use it in GitHub Desktop.
for start := time.Now(); time.Since(start) < time.Second; {
foo();
}
loop:
for timeout := time.After(time.Second); ; {
select {
case <-timeout:
fmt.Println("x")
break loop
default:
}
foo();
}
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