Skip to content

Instantly share code, notes, and snippets.

@tigercallme
Last active October 20, 2017 13:27
Show Gist options
  • Save tigercallme/6dcadeeef208a62d8c8085814a4d0f4f to your computer and use it in GitHub Desktop.
Save tigercallme/6dcadeeef208a62d8c8085814a4d0f4f to your computer and use it in GitHub Desktop.
Go小技巧-使用select{}阻塞main函数
// 很多时候我们需要让main函数不退出,让它在后台一直执行,例如:
func main() {
for i := 0; i < 20; i++ { //启动20个协程处理消息队列中的消息
c := consumer.New()
go c.Start()
}
select {} // 阻塞
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment