Skip to content

Instantly share code, notes, and snippets.

@kschaper
Last active March 21, 2024 14:02
Show Gist options
  • Save kschaper/cf96bb7475b833446ed93dfcfae781c2 to your computer and use it in GitHub Desktop.
Save kschaper/cf96bb7475b833446ed93dfcfae781c2 to your computer and use it in GitHub Desktop.
CPU friendly infinite loop in Go
// CPU friendly
for {
select {
case <-time.After(time.Second):
// do something
}
}
// instead of busy loop
for {
time.Sleep(time.Second)
// do something
}
@aeon3k
Copy link

aeon3k commented Nov 27, 2023

My CPU thanks you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment