cancel() public static method

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.
return void
コード例 #1
0
ファイル: Pause.php プロジェクト: koolkode/async
 /**
  * {@inheritdoc}
  */
 public function cancel(\Throwable $e) : array
 {
     if ($this->state === self::PENDING) {
         Loop::cancel($this->watcher);
         $this->fail($e);
     }
     return [];
 }
コード例 #2
0
ファイル: FilesystemObserver.php プロジェクト: koolkode/async
 /**
  * {@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
ファイル: SocketWriterTrait.php プロジェクト: koolkode/async
 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
ファイル: Timeout.php プロジェクト: koolkode/async
 /**
  * {@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
ファイル: SocketReaderTrait.php プロジェクト: koolkode/async
 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
ファイル: WriteBytes.php プロジェクト: koolkode/async
 /**
  * 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;
         }
     });
 }