/** * Register the callback call into the event loop. * * @param array $parameters * @return void */ public function call(array $parameters = []) { $callback = $this->getCallback(); $realCallback = function () use($callback, $parameters) { call_user_func_array($callback, $parameters); // todo : fix with PHP 5.6 argument unpacking }; $resource = \uv_async_init($this->getLoop()->getBackend(), $realCallback); \uv_async_send($resource); }
public function nextTick($callback) { $loop = $this->getSystem()->getEventLoop(); $plugin = $this; $plugin->addTickCallback($callback); $tick = $this->tick; if ($tick == 1) { $f = function ($r, $status) use($plugin, &$tick) { $callback = $plugin->getTickCallback($tick); if (is_callable($callback)) { call_user_func($callback); $plugin->removeTickCallback($tick); $tick++; uv_async_send($r); } else { uv_close($r); } }; $r = uv_async_init($loop, $f); uv_async_send($r); } }
<?php $loop = uv_default_loop(); $async = uv_async_init($loop, function ($async, $status) { var_dump(1); uv_close($async); }); uv_async_send($async); uv_run();