Go: Make a goroutine block or sleep forever

An empty select statement blocks forever.

select {} // block forever

This is useful if you have a long running goroutine (such as a server serving requests) and want to prevent the main thread from falling off the edge.

This works since select statements block until at least one of it's cases become unblocked. With zero cases this will never happen.

Comments

Be the first to comment!