Skip to content

Releases: WyriHaximus/reactphp-awaitable-observable

1.1.0

30 Nov 22:08
b942237
Compare
Choose a tag to compare

1.0.0

13 Aug 09:27
d8423f5
Compare
Choose a tag to compare

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�sync;
use function WyriHaximus\React�waitObservable;

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�sync;
use function WyriHaximus\React�waitObservable;

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();
        }
    }
});

1.0.0

  • Total issues resolved: 0
  • Total pull requests resolved: 29
  • Total contributors: 2

Bug 🐞,Enhancement ✨

Dependabot 🤖,Enhancement ✨

Enhancement ✨,Feature 🏗

Enhancement ✨