Interop\Async\Loop::enable PHP Метод

enable() публичный статический Метод

Watchers (enabling or new watchers) MUST immediately be marked as enabled, but only be activated (i.e. callbacks can be called) right before the next tick. Callbacks of watchers MUST not be called in the tick they were enabled.
public static enable ( string $watcherId ) : void
$watcherId string The watcher identifier.
Результат void
    public static function enable($watcherId)
    {
        $driver = self::$driver ?: self::get();
        $driver->enable($watcherId);
    }

Usage Example

Пример #1
0
 public function write(string $bytes) : Awaitable
 {
     if ($bytes === '') {
         if (!\is_resource($this->socket)) {
             return new Failure(new StreamClosedException('Socket resource unavailable'));
         }
         return new Success(0);
     }
     $len = \strlen($bytes);
     if (!$this->writerEnabled) {
         try {
             $bytes = $this->writeBytes($bytes);
         } catch (\Throwable $e) {
             return new Failure($e);
         }
         if ($bytes === '') {
             return new Success($len);
         }
         $this->writerEnabled = true;
         if ($this->pendingWrites === null) {
             $this->pendingWrites = new \SplQueue();
         }
         if ($this->writeWatcher === null) {
             $this->writeWatcher = Loop::onWritable($this->socket, $this->createWriteWatcher());
         } else {
             try {
                 Loop::enable($this->writeWatcher);
             } catch (InvalidWatcherException $e) {
                 $this->writeWatcher = Loop::onWritable($this->socket, $this->createWriteWatcher());
             }
         }
         if (!$this->writerReferenced) {
             Loop::unreference($this->writeWatcher);
         }
     }
     $this->pendingWrites->enqueue($write = new PendingWrite($bytes, $len, function () {
         foreach ($this->pendingWrites as $write) {
             if (!$write->disabled) {
                 return;
             }
         }
         $this->writerEnabled = false;
         Loop::disable($this->writeWatcher);
     }));
     return $write;
 }
All Usage Examples Of Interop\Async\Loop::enable