Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

读取MessageChannel不用判断下是否close了嘛? #1

Open
leedstyh opened this issue Sep 28, 2020 · 2 comments
Open

读取MessageChannel不用判断下是否close了嘛? #1

leedstyh opened this issue Sep 28, 2020 · 2 comments

Comments

@leedstyh
Copy link

func (u *User) SendMessage(ctx context.Context) {
	for msg := range u.MessageChannel {
		wsjson.Write(ctx, u.conn, msg)
	}
}

你这样的话,MessageChannel close了的话,这里不是一直循环

@lucky51
Copy link

lucky51 commented Jun 14, 2021

close 之后 就退出了,还循环个啥。

@zjfsdnu
Copy link

zjfsdnu commented Jul 15, 2021

close channel后 for range 会自动退出的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants