Converts an existing observable sequence to React Promise
public static fromObservable ( Rx\ObservableInterface $observable, |
||
$observable | Rx\ObservableInterface | |
$deferred | ||
리턴 |
/** * @test * */ public function promise_failure() { $source = new Subject(); $source->onError(new Exception("some error")); $promise = Promise::fromObservable($source); $promise->then(function ($value) { $this->assertTrue(false); }, function ($error) { $this->assertEquals($error, new Exception("some error")); }); }
<?php require_once __DIR__ . '/../bootstrap.php'; // With React Promise $source = \Rx\Observable\BaseObservable::just(42); $promise = \Rx\React\Promise::fromObservable($source); $promise->then(function ($value) { echo "Value {$value}\n"; }); //Value 42
/** * @return array */ public function broadcasts() : array { return await(Promise::fromObservable($this->client->broadcasts()->toArray()), $this->transport->getLoop()); }