Skip to content

2.0.0

Latest
Compare
Choose a tag to compare
@github-actions github-actions released this 09 Feb 12:22
8bd9ec8

Fully reworked the event loop public facing API to utilize fibers:

Channels

From:

use parallel\Channel;
use React�ventLoop\Factory;
use ReactParallel�ventLoop�ventLoopBridge;

$loop = Factory::create();
$eventLoopBridge = new EventLoopBridge($loop);

$channel = new Channel(Channel::Infinite);
$eventLoopBridge->observe($channel)->subscribe(function (string $message) {
    echo $message, PHP_EOL;
});

$loop->futureTick(function () use ($channel): void {
    $channel->send('Hello World!');
    $channel->close();
});

$loop->run();

To:

use parallel\Channel;
use React�ventLoop\Loop;
use ReactParallel�ventLoop�ventLoopBridge;
use function React\Async�sync;
use function React\Async�wait;
use function React\Promise\Timer\sleep;

$eventLoopBridge = new EventLoopBridge();

Loop::futureTick(async(static function () use ($eventLoopBridge) {
    /** @var Channel<string> */
    $channel = new Channel(Channel::Infinite);

    Loop::futureTick(async(function () use ($channel): void {
        $channel->send('Hello World!');
        // Don't close the channel right after writing to it,
        // as it will be closed on both ends and the other
        // thread won't receive your message
        await(sleep(1));
        $channel->close();
    }));

    foreach ($eventLoopBridge->observe($channel) as $message) {
        echo $message, PHP_EOL;
    }
}));

Futures

From:

use parallel\Channel;
use React�ventLoop\Factory;
use ReactParallel�ventLoop�ventLoopBridge;
use function parallel
un;

$loop = Factory::create();
$eventLoopBridge = new EventLoopBridge($loop);

$future = run(function (): string {
    return 'Hello World!';
});

$channel = new Channel(Channel::Infinite);
$eventLoopBridge->await($future)->then(function (string $message) {
    echo $message, PHP_EOL;
});

$loop->run();

To:

use React�ventLoop\Loop;
use ReactParallel�ventLoop�ventLoopBridge;
use function parallel
un;
use function React\Async�sync;

$eventLoopBridge = new EventLoopBridge();

Loop::futureTick(async(static function () use ($eventLoopBridge) {
    $future = run(function (): string {
        return 'Hello World!';
    });

    echo $eventLoopBridge->await($future), PHP_EOL;
}));

2.0.0

  • Total issues resolved: 0
  • Total pull requests resolved: 36
  • Total contributors: 3

Dependencies 📦,Enhancement ✨

Dependencies 📦,Feature 🏗

Dependencies 📦

Enhancement ✨