Ejemplo n.º 1
0
 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);
         }
     };
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
Ejemplo n.º 3
0
 /**
  * Initialize the loop
  *
  * @return LoopInterface
  */
 public function init()
 {
     $this->loop = \uv_loop_new();
     return $this;
 }