当前位置: 首页>>代码示例>>PHP>>正文


PHP Deferred::resolver方法代码示例

本文整理汇总了PHP中React\Promise\Deferred::resolver方法的典型用法代码示例。如果您正苦于以下问题:PHP Deferred::resolver方法的具体用法?PHP Deferred::resolver怎么用?PHP Deferred::resolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在React\Promise\Deferred的用法示例。


在下文中一共展示了Deferred::resolver方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send

 /**
  * Transforms a message to the format requested by DaZeus and sends it
  * @param  mixed   $data     The data to be send, should be some stdObject or associative array
  * @param  boolean $callback Callback that receives the response, true for an
  *                           empty callback, false if no callback is expected
  * @return PromiseInterface
  */
 public function send($data, $callback = true)
 {
     if (is_callable($callback) || $callback === true) {
         $deferred = new Deferred();
         $deferred->then(function ($message) use($callback) {
             if (is_callable($callback)) {
                 return $callback($message);
             }
             return $message;
         });
         $this->watchers[] = $deferred->resolver();
         $this->sendData($data);
         return $deferred->promise();
     } else {
         $this->sendData($data);
         return new FulfilledPromise();
     }
 }
开发者ID:dazeus,项目名称:dazeus-php,代码行数:25,代码来源:Connection.php

示例2: query

 public function query($nameserver, Query $query)
 {
     $deferred = new Deferred();
     $this->tryQuery($nameserver, $query, $this->retries, $deferred->resolver());
     return $deferred->promise();
 }
开发者ID:pvelly,项目名称:CGParty,代码行数:6,代码来源:RetryExecutor.php

示例3: handleConnectedSocks

 public function handleConnectedSocks(Stream $stream, $host, $port, $timeout, $protocolVersion, $auth = null)
 {
     $deferred = new Deferred();
     $resolver = $deferred->resolver();
     $timerTimeout = $this->loop->addTimer($timeout, function () use($resolver) {
         $resolver->reject(new Exception('Timeout while establishing socks session'));
     });
     if ($protocolVersion === '5' || $auth !== null) {
         $promise = $this->handleSocks5($stream, $host, $port, $auth);
     } else {
         $promise = $this->handleSocks4($stream, $host, $port);
     }
     $promise->then(function () use($resolver, $stream) {
         $resolver->resolve($stream);
     }, function ($error) use($resolver) {
         $resolver->reject(new Exception('Unable to communicate...', 0, $error));
     });
     $loop = $this->loop;
     $deferred->then(function (Stream $stream) use($timerTimeout, $loop) {
         $loop->cancelTimer($timerTimeout);
         $stream->removeAllListeners('end');
         return $stream;
     }, function ($error) use($stream, $timerTimeout, $loop) {
         $loop->cancelTimer($timerTimeout);
         $stream->close();
         return $error;
     });
     $stream->on('end', function (Stream $stream) use($resolver) {
         $resolver->reject(new Exception('Premature end while establishing socks session'));
     });
     return $deferred->promise();
 }
开发者ID:Sitronik,项目名称:php-socks,代码行数:32,代码来源:Client.php


注:本文中的React\Promise\Deferred::resolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。