Ratchet WampServerInterface和计时器

时间:2013-09-10 13:33:42

标签: timer ratchet

我想知道是否有办法从WampServerInterface实例启动计时器?

我看到你可以在服务器对象上设置它。但是如果有人订阅某个事件,我需要从我的WanpServerInterface对象创建它。

有什么难事吗?

此致

2 个答案:

答案 0 :(得分:1)

Timer是循环对象上的一个函数,因此可以通过获取循环对象来调用它。但由于文档非常简约,我花了一些时间才找到答案(几个小时甚至更长时间)并回到这里。

class MyObject implements WampServerInterface
{
 ...
 $this->loop->addPeriodicTimer(2, function($timer) { call_user_func(array($this, 'startCountdown'), $timer); }) ;
...
}

答案 1 :(得分:0)

您可以将在IoServer中传递/创建的EventLoop注入您的WAMP应用程序,并在用户订阅您想要的主题后使用它创建计时器。