本文整理汇总了PHP中Rx\Observable::subscribeCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::subscribeCallback方法的具体用法?PHP Observable::subscribeCallback怎么用?PHP Observable::subscribeCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::subscribeCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: observe
public function observe(Observable $observable)
{
return $observable->subscribeCallback(function (Event $event) {
//$name = basename(str_replace('\\', '/', (is_object($event) ? get_class($event) : $event)));
//\Log::info("{$this->preposition} {$name} {$event->name}", $event->labels);
if ($this->verbosity == 4) {
$this->dump($event->data);
}
}, function ($e) {
if ($this->verbosity == 4) {
//\Log::error("{$this->preposition} {$e->getMessage()}");
} else {
//\Log::error("{$this->preposition} {$e->getMessage()}", [$e]);
}
}, function () {
//\Log::warning("{$this->preposition} event stream is complete");
});
}
示例2: awaitOnce
/**
* @param Observable $observable
* @param LoopInterface|null $loop
* @return null
* @throws \Exception
*/
function awaitOnce(Observable $observable, LoopInterface $loop = null)
{
$loop = $loop ?: \EventLoop\getLoop();
$done = false;
$res = null;
$observable->subscribeCallback(function ($el) use(&$done, &$res) {
$res = $el;
$done = true;
}, function ($e) use(&$done, &$res) {
$res = $e;
$done = true;
}, function () use(&$done) {
$done = true;
}, new EventLoopScheduler($loop));
while (!$done) {
$loop->tick();
}
if ($res instanceof \Exception) {
throw $res;
}
return $res;
}