本文整理汇总了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();
}
}
示例2: query
public function query($nameserver, Query $query)
{
$deferred = new Deferred();
$this->tryQuery($nameserver, $query, $this->retries, $deferred->resolver());
return $deferred->promise();
}
示例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();
}