当前位置: 首页>>代码示例>>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;未经允许,请勿转载。