Skip to content

2.0.0

Closed
No due date
Closed Feb 9, 2025
100% complete

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

Channels

From:

use parallel\Channel;
use React\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;

$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\EventLoop\Loop;
use ReactParallel\EventLoop\EventLoopBridge;
use function React\Async\async;
use function React\Async\await;
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\EventLoop\Factory;
use ReactParallel\EventLoop\EventLoopBridge;
use function parallel\run;

$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\EventLoop\Loop;
use ReactParallel\EventLoop\EventLoopBridge;
use function parallel\run;
use function React\Async\async;

$eventLoopBridge = new EventLoopBridge();

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

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

List view

There are no open issues in this milestone

Add issues to milestones to help organize your work for a particular release or project. Find and add issues with no milestones in this repo.