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

如何让comment在指定的goroutine中运行? #51

Closed
github-yxb opened this issue Dec 18, 2019 · 2 comments
Closed

如何让comment在指定的goroutine中运行? #51

github-yxb opened this issue Dec 18, 2019 · 2 comments
Labels

Comments

@github-yxb
Copy link

1.我想让不同的comment在不同的goroutine中运行,但是
只看到了handler中的localProcess的注释和schd的定义,
但是没有example,希望可以写个eample演示一下.万分感谢

2.看了下关于分布式的实现,很想知道为什么不用成熟的etcd,consul方案,需要自己实现一下注册中心呢?

@lonng
Copy link
Owner

lonng commented Dec 18, 2019

@github-yxb 可以在 session 变量中保存一个 Scheduler,然后把相关的代码调度到对应的 goroutine 中。

  1. 注册 service 的时候添加一个调度器的名字,component.WithSchedulerName("room")
  2. 当 session 绑定一个 room 的时候,可以在 session 上绑定这个 room,session.Set("room", currentRoom)
  3. room 这个类上面需要实现
// LocalScheduler schedules task to a customized goroutine
type LocalScheduler interface {
	Schedule(Task)
}

这样就会把这个 task 放到这个 session 对应的房间线程执行。

@github-yxb
Copy link
Author

多谢回复!
大致明白了流程,即新链接session需在全局goroutine中做绑定后,后面的消息将由自定义goroutine处理。

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

No branches or pull requests

2 participants