本文整理汇总了PHP中Rx\Observable::error方法的典型用法代码示例。如果您正苦于以下问题:PHP Observable::error方法的具体用法?PHP Observable::error怎么用?PHP Observable::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rx\Observable
的用法示例。
在下文中一共展示了Observable::error方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: timestamp_error
/**
* @test
*/
public function timestamp_error()
{
$error = new \Exception();
$results = $this->scheduler->startWithCreate(function () use($error) {
return Observable::error($error)->timestamp($this->scheduler);
});
$this->assertMessages([onError(201, $error)], $results->getMessages());
}
示例2: await_rejected
/**
* @test
* @expectedException \Exception
*/
public function await_rejected()
{
$observable = Observable::error(new \Exception());
$generator = \Rx\await($observable);
foreach ($generator as $item) {
$this->assertTrue(false);
//should never get here
}
}
示例3: __invoke
/**
* @param \Rx\ObservableInterface $observable
* @param \Rx\ObserverInterface $observer
* @param \Rx\SchedulerInterface $scheduler
* @return \Rx\DisposableInterface
*/
public function __invoke(ObservableInterface $observable, ObserverInterface $observer, SchedulerInterface $scheduler = null)
{
$factory = $this->factory;
try {
$result = $factory();
} catch (\Exception $e) {
return Observable::error($e)->subscribe($observer, $scheduler);
}
return $result->subscribe($observer, $scheduler);
}
示例4: testWithImmediateSchedulerWithRecursion
public function testWithImmediateSchedulerWithRecursion()
{
$completed = false;
$emitted = null;
Observable::range(0, 10)->flatMap(function ($x) use(&$count) {
if (++$count < 2) {
return Observable::error(new \Exception("Something"));
}
return Observable::just(42);
})->retry(3)->take(1)->subscribe(new CallbackObserver(function ($x) use(&$emitted) {
$emitted = $x;
}, null, function () use(&$completed) {
$completed = true;
}), new ImmediateScheduler());
$this->assertTrue($completed);
$this->assertEquals(42, $emitted);
}
示例5: Exception
<?php
require_once __DIR__ . '/../bootstrap.php';
$source = \Rx\Observable::error(new Exception('Oops'))->doOnError(function (Exception $err) {
echo 'Do Error:', $err->getMessage(), PHP_EOL;
});
$subscription = $source->subscribe($stdoutObserver);
示例6: average
/**
* Computes the average of an observable sequence of values.
*
* @return AnonymousObservable
*
* @demo average/average.php
* @operator
* @reactivex average
*/
public function average()
{
return $this->defaultIfEmpty(Observable::error(new \UnderflowException()))->reduce(function ($a, $x) {
static $count = 0;
static $total = 0;
$count++;
$total += $x;
return $total / $count;
}, 0);
}
示例7: Exception
<?php
require_once __DIR__ . '/../bootstrap.php';
$obs2 = Rx\Observable::just(42);
$source = \Rx\Observable::error(new Exception("Some error"))->catchError(function (Exception $e, \Rx\Observable $sourceObs) use($obs2) {
return $obs2;
});
$subscription = $source->subscribe($stdoutObserver);
示例8: Exception
<?php
require __DIR__ . '/../vendor/autoload.php';
$source = \Rx\Observable::error(new Exception('some error'));
$generator = \Rx\await($source);
try {
foreach ($generator as $item) {
echo $item, PHP_EOL;
}
} catch (\Exception $e) {
echo "caught error: ", $e->getMessage();
}
示例9: concatMap_Then_Error_Task
/**
* @test
*/
public function concatMap_Then_Error_Task()
{
$xs = Observable::fromArray([4, 3, 2, 1]);
$results = [];
$completed = false;
$error = false;
$xs->concatMap(function ($x, $i) {
return Observable::error(new Exception($x + $i));
})->subscribeCallback(function ($x) use(&$results) {
$results[] = $x;
}, function (\Exception $e) use(&$results, &$error) {
$error = true;
$this->assertEquals(4, $e->getMessage());
}, function () use(&$completed) {
$completed = true;
});
$this->assertFalse($completed);
$this->assertTrue($error);
}
示例10: testConcatAllError
public function testConcatAllError()
{
$sources = Observable::fromArray([Observable::just(0), Observable::error(new \Exception()), Observable::just(2), Observable::just(3)]);
$res = [];
$error = false;
$completed = false;
$sources->concatAll()->subscribeCallback(function ($x) use(&$res) {
$res[] = $x;
}, function ($e) use(&$res, &$error) {
$this->assertEquals([0], $res);
$error = true;
}, function () use(&$completed) {
$completed = true;
});
$this->assertTrue($error);
$this->assertFalse($completed);
}