/** * Constructor. Accepts as an argument the loop on which the idler will run. * * @param BaseLoopInterface $loop * @throws InvalidLoopInstance */ public function __construct(BaseLoopInterface $loop) { if (!$loop instanceof LoopInterface) { throw new InvalidLoopInstance('Loop instance does not use the Libuv adapter.'); } $this->setLoop($loop); $this->idler = \uv_idle_init($this->getLoop()->getBackend()); }
<?php $loop = uv_default_loop(); $idle = uv_idle_init(); $i = 0; uv_idle_start($idle, function ($stat) use(&$i, $idle, $loop) { echo "count: {$i}" . PHP_EOL; $i++; if ($i > 3) { uv_idle_stop($idle); uv_unref($idle); } sleep(1); }); uv_run(); echo "finished";