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


PHP Observable::error方法代码示例

本文整理汇总了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());
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:11,代码来源:TimestampTest.php

示例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
     }
 }
开发者ID:RxPHP,项目名称:RxAwait,代码行数:13,代码来源:FunctionAwaitTest.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:16,代码来源:DeferOperator.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:17,代码来源:RetryTest.php

示例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);
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:7,代码来源:doOnError.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:19,代码来源:Observable.php

示例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);
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:8,代码来源:catchError.php

示例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();
}
开发者ID:RxPHP,项目名称:RxAwait,代码行数:12,代码来源:errors.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:22,代码来源:ConcatMapTest.php

示例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);
 }
开发者ID:ReactiveX,项目名称:RxPHP,代码行数:17,代码来源:ConcatTest.php


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