當前位置: 首頁>>代碼示例>>PHP>>正文


PHP LoopInterface::addWriteStream方法代碼示例

本文整理匯總了PHP中React\EventLoop\LoopInterface::addWriteStream方法的典型用法代碼示例。如果您正苦於以下問題:PHP LoopInterface::addWriteStream方法的具體用法?PHP LoopInterface::addWriteStream怎麽用?PHP LoopInterface::addWriteStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在React\EventLoop\LoopInterface的用法示例。


在下文中一共展示了LoopInterface::addWriteStream方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addWriteStream

 /**
  * Register a listener to be notified when a stream is ready to write.
  *
  * @param stream $stream The PHP stream resource to check.
  * @param callable $listener Invoked when the stream is ready.
  */
 public function addWriteStream($stream, callable $listener)
 {
     $this->emit('addWriteStream', [$stream, $listener]);
     $this->loop->addWriteStream($stream, function ($stream) use($listener) {
         $this->emit('writeStreamTick', [$stream, $listener]);
         $listener($stream, $this);
     });
 }
開發者ID:WyriHaximus,項目名稱:reactphp-event-loop-inspector,代碼行數:14,代碼來源:LoopDecorator.php

示例2: send

 /**
  * @param string $message
  */
 public function send($message)
 {
     if ($this->closed) {
         return;
     }
     $this->messages[] = $message;
     if (!$this->listening) {
         $this->listening = true;
         $this->loop->addWriteStream($this->fileDescriptor, $this->writeListener);
     }
 }
開發者ID:siosphere,項目名稱:zmq,代碼行數:14,代碼來源:Buffer.php

示例3: add

 /**
  * Add event listener to event loop.
  *
  * @param $fd
  * @param $flag
  * @param $func
  * @param array $args
  * @return bool
  */
 public function add($fd, $flag, $func, $args = array())
 {
     switch ($flag) {
         case EventInterface::EV_READ:
             return $this->_loop->addReadStream($fd, $func);
         case EventInterface::EV_WRITE:
             return $this->_loop->addWriteStream($fd, $func);
         case EventInterface::EV_SIGNAL:
             return $this->_loop->addSignal($fd, $func);
         case EventInterface::EV_TIMER:
             return $this->_loop->addPeriodicTimer($fd, $func);
         case EventInterface::EV_TIMER_ONCE:
             return $this->_loop->addTimer($fd, $func);
     }
     return false;
 }
開發者ID:walkor,項目名稱:workerman,代碼行數:25,代碼來源:React.php

示例4: testRunWaitsForFutureTickEvents

 public function testRunWaitsForFutureTickEvents()
 {
     $stream = $this->createStream();
     $this->loop->addWriteStream($stream, function () use($stream) {
         $this->loop->removeStream($stream);
         $this->loop->futureTick(function () {
             echo 'future-tick' . PHP_EOL;
         });
     });
     $this->expectOutputString('future-tick' . PHP_EOL);
     $this->loop->run();
 }
開發者ID:smileytechguy,項目名稱:nLine,代碼行數:12,代碼來源:AbstractLoopTest.php

示例5: onWritable

 /**
  * Watch a stream resource to become writable and trigger the callback when actionable
  *
  * @param resource $stream A stream resource to watch for writability
  * @param callable $callback Any valid PHP callable
  * @param bool $enableNow Should the watcher be enabled now or held for later use?
  * @return int
  */
 public function onWritable($stream, callable $callback, $enableNow = true)
 {
     $watcherId = null;
     $this->reactor->addWriteStream($stream, function () use($callback, &$watcherId, $stream) {
         if (isset($this->disabledWatchers[$watcherId])) {
             return null;
         }
         return call_user_func($callback, $watcherId, $stream, $this);
     });
     $watcherId = $this->registerWatcher(self::WATCHER_TYPE_WRITE, $stream);
     if (!$enableNow) {
         $this->disable($watcherId);
     }
     return $watcherId;
 }
開發者ID:daverandom,項目名稱:loopio,代碼行數:23,代碼來源:Loop.php

示例6: flushWriteBuffer

 /**
  * Asynchronously sends buffered data over the wire.
  *
  * - Calls {@link eventLoops}'s addWriteStream() with client's stream.
  * - Consecutive calls will return the same instance of promise.
  *
  * @return Promise\PromiseInterface
  */
 protected function flushWriteBuffer()
 {
     if ($this->flushWriteBufferPromise) {
         return $this->flushWriteBufferPromise;
     } else {
         $deferred = new Promise\Deferred();
         $this->eventLoop->addWriteStream($this->getStream(), function ($stream) use($deferred) {
             try {
                 $this->write();
                 if ($this->writeBuffer->isEmpty()) {
                     $this->eventLoop->removeWriteStream($stream);
                     $this->flushWriteBufferPromise = null;
                     $deferred->resolve(true);
                 }
             } catch (\Exception $e) {
                 $this->eventLoop->removeWriteStream($stream);
                 $this->flushWriteBufferPromise = null;
                 $deferred->reject($e);
             }
         });
         return $this->flushWriteBufferPromise = $deferred->promise();
     }
 }
開發者ID:Andrewsville,項目名稱:bunny,代碼行數:31,代碼來源:Client.php


注:本文中的React\EventLoop\LoopInterface::addWriteStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。