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

This will detatch the event loop from all resources that are associated to the watcher. After this operation the watcher is permanently invalid. Calling this function MUST NOT fail, even if passed an invalid watcher.
public static cancel ( string $watcherId ) : void
$watcherId string The watcher identifier.
Результат void
Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function cancel(\Throwable $e) : array
 {
     if ($this->state === self::PENDING) {
         Loop::cancel($this->watcher);
         $this->fail($e);
     }
     return [];
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function cancelObserver(string $watcherId)
 {
     if (isset($this->watchers[$watcherId])) {
         unset($this->watchers[$watcherId]);
         if (empty($this->watchers)) {
             Loop::cancel($this->timer);
         }
     }
 }
Пример #3
0
 protected function disposeWriter(\Throwable $e = null)
 {
     $this->writerEnabled = false;
     if ($this->writeWatcher !== null) {
         try {
             Loop::cancel($this->writeWatcher);
         } finally {
             $this->writeWatcher = null;
         }
     }
     if ($this->pendingWrites) {
         while (!$this->pendingWrites->isEmpty()) {
             $write = $this->pendingWrites->dequeue();
             if (!$write->disabled) {
                 $write->fail($e ?? new StreamClosedException('Socket writer disposed'));
             }
         }
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function cancel(\Throwable $e) : array
 {
     if ($this->state === self::PENDING) {
         Loop::cancel($this->watcher);
         try {
             if ($this->promise instanceof Awaitable) {
                 $this->state = self::FAILED;
                 try {
                     return $this->promise->cancel($e);
                 } finally {
                     $this->state = self::PENDING;
                 }
             }
         } finally {
             $this->fail($e);
         }
     }
     return [];
 }
Пример #5
0
 protected function disposeReader(\Throwable $e = null)
 {
     $this->readerEnabled = false;
     if ($this->readWatcher !== null) {
         try {
             Loop::cancel($this->readWatcher);
         } finally {
             $this->readWatcher = null;
         }
     }
     if ($this->pendingReads) {
         while (!$this->pendingReads->isEmpty()) {
             $read = $this->pendingReads->dequeue();
             if (!$read->disabled) {
                 $read->fail($e ?? new StreamClosedException('Socket reader disposed'));
             }
         }
     }
     return $this->readBuffer;
 }
Пример #6
0
 /**
  * Write bytes to the stream, register a writable watcher if not all bytes could be written.
  * 
  * @param resource $stream Resource to be written to.
  * @param string $bytes Bytes to be written.
  * @param int $chunkSize Write data chunk size.
  */
 protected function writeBytesToStream($stream, string $bytes, int $chunkSize)
 {
     $len = 0;
     try {
         if ($this->writeBytes($stream, $len, $bytes, $chunkSize)) {
             return $this->resolve($len);
         }
     } catch (\Throwable $e) {
         return $this->fail($e);
     }
     $retry = false;
     $this->watcher = Loop::onWritable($stream, function ($watcherId) use(&$len, &$bytes, &$retry, $stream, $chunkSize) {
         try {
             $length = $len;
             if ($this->writeBytes($stream, $len, $bytes, $chunkSize)) {
                 $this->watcher = null;
                 Loop::cancel($watcherId);
                 $retry = false;
                 return $this->resolve($len);
             }
             if ($retry && $length === $len) {
                 throw new StreamClosedException('Write failed after retry, assuming broken pipe');
             }
         } catch (\Throwable $e) {
             $this->watcher = null;
             Loop::cancel($watcherId);
             return $this->fail($e);
         }
         if ($length === $len) {
             $retry = true;
         }
     });
 }