1.0.0
Closed Aug 13, 2022
100% complete
Usage
The awaitObservable
function will accept any observable and turn it into an iterator, so it can be used inside
async
in an foreach
:
use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;
use function React\Async\async;
use function WyriHaximus\React\awaitObservable;
async(function () {
$observable = Observable::fromArray(range(0, 1337), new I…
Usage
The awaitObservable
function will accept any observable and turn it into an iterator, so it can be used inside
async
in an foreach
:
use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;
use function React\Async\async;
use function WyriHaximus\React\awaitObservable;
async(function () {
$observable = Observable::fromArray(range(0, 1337), new ImmediateScheduler());
foreach (awaitObservable($observable) as $integer) {
echo $integer; // outputs 01234....13361337
}
});
Breaking the iterator
The example above assumes you won't break the iterator. There are however situations where you want to short circuit
the iterator, for such situations the break
method is provided.
use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;
use function React\Async\async;
use function WyriHaximus\React\awaitObservable;
async(function () {
$observable = Observable::fromArray(range(0, 1337), new ImmediateScheduler());
$iterator = awaitObservable($observable);
foreach ($iterator as $integer) {
echo $integer; // outputs 01234
if ($integer >= 4) {
$iterator->break();
}
}
});
This milestone is closed.
No open issues remain. View closed issues or see open milestones in this repository.