## Timer 一次性定时 ~~~ use Mix\Time\Time; $timer = Time::newTimer(1 * Time::SECOND); xgo(function () use ($timer) { $ts = $timer->channel()->pop(); println($ts); }); ~~~ | 方法 | 描述 | | --- | --- | | stop() | 停止 | | reset(int $duration) | 重置 | | channel(): Mix\Coroutine\Channel | 获取通道 | ## Ticker 持续定时,10 次后停止 ~~~ use Mix\Time\Time; $ticker = Time::newTicker(1 * Time::SECOND); xgo(function () use ($ticker) { $count = 0; while (true) { $ts = $ticker->channel()->pop(); if (!$ts || $count == 10) { $ticker->stop(); return; } println($ts); $count++; } }); ~~~ | 方法 | 描述 | | --- | --- | | stop() | 停止 | | channel(): Mix\Coroutine\Channel | 获取通道 |