Last active
October 20, 2017 13:27
-
-
Save tigercallme/6dcadeeef208a62d8c8085814a4d0f4f to your computer and use it in GitHub Desktop.
Go小技巧-使用select{}阻塞main函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 很多时候我们需要让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