public function __construct() { // @codeCoverageIgnoreStart if (!\extension_loaded("uv")) { throw new \RuntimeException("The php-uv extension is required to use " . __CLASS__); } // @codeCoverageIgnoreEnd $this->loop = \uv_loop_new(); $this->isWindows = stripos(PHP_OS, 'win') === 0; /** * Prior to PHP7 we can't cancel closure watchers inside their own callbacks * because PHP will fatal. In legacy versions we schedule manual GC workarounds. * * @link https://bugs.php.net/bug.php?id=62452 */ if (PHP_MAJOR_VERSION < 7) { $this->garbage = []; $this->gcWatcher = \uv_timer_init($this->loop); $this->gcCallback = function () { $this->garbage = []; $this->isGcScheduled = false; }; } $this->onCoroutineResolution = function ($e = null, $r = null) { if ($e) { $this->onCallbackError($e); } }; }
/** * @param bool $enableSignals True to enable signal handling, false to disable. * @param resource|null $loop Resource created by uv_loop_new() or null to create a new event loop. * * @throws \Icicle\Exception\UnsupportedError If the uv extension is not loaded. */ public function __construct(bool $enableSignals = true, $loop = null) { // @codeCoverageIgnoreStart if (!extension_loaded('uv')) { throw new UnsupportedError(__CLASS__ . ' requires the UV extension.'); } // @codeCoverageIgnoreEnd // @codeCoverageIgnoreStart if (!is_resource($loop)) { $this->loopHandle = \uv_loop_new(); } else { // @codeCoverageIgnoreEnd $this->loopHandle = $loop; } parent::__construct($enableSignals); }
/** * Initialize the loop * * @return LoopInterface */ public function init() { $this->loop = \uv_loop_new(); return $this; }