How does a select statement with a default case enable non-blocking channel operations?

Last updated 20 June 2026

  • A plain select blocks until some send or receive case is ready. Adding a default case makes it run that branch immediately when no channel is ready, so it never blocks.

  • Typical uses: non-blocking receive, non-blocking send (drop if the buffer is full), and polling a done/quit channel inside a loop.

  • Caveat: looping tightly on default busy-spins the CPU, so add a timer or backoff.

  • https://dev.to/crusty0gphr/tricky-golang-interview-questions-part-6-nonblocking-read-aj1
  • https://www.geeksforgeeks.org/go-language/golang-deadlock-and-default-case-in-select-statement/
  • https://www.freecodecamp.org/news/real-time-systems-for-web-developers-from-theory-to-a-live-go-react-app/
All Golang interview questions