4 ms·
This just happened to me. I wanted to run a goroutine and then not exit the program, so I ran an empty for loop and it didn’t work. Would a for{ continue } have
by the_clarence 8y ago
This just happened to me. I wanted to run a goroutine and then not exit the program, so I ran an empty for loop and it didn’t work. Would a for{ continue } have work?
- deleted 8y ago[deleted]
- grose 8y agoYou can use select{} to block forever and yield the goroutine.
- the_clarence 8y agoYield?
- majewsky 8y ago`for { continue }` is semantically equivalent to `for {}` since the closing bracket of the loop block implies a `continue`. As a sibling correctly notes, `select {}` is what you want to do instead. You need to do something that can block the goroutine in such a way that control returns to the scheduler. Selecting is one of those ways.