@@ -23,39 +23,31 @@ event loop, that will work, but it adds additional overhead when you have more t
2323different major contexts. Share this bridge around so that other packages can use them, and only have one instance
2424checking for events.
2525
26- ``` php
27- use React\EventLoop\Factory;
28- use ReactParallel\EventLoop\EventLoopBridge;
29-
30- $loop = Factory::create();
31- $eventLoopBridge = new EventLoopBridge($loop);
32-
33- $loop->run();
34- ```
35-
3626## Channels
3727
3828Channels often have a stream of messages going over them, as such the bridge will convert them into an observable.
3929
4030``` php
4131use parallel\Channel;
42- use React\EventLoop\Factory ;
32+ use React\EventLoop\Loop ;
4333use ReactParallel\EventLoop\EventLoopBridge;
34+ use function React\Async\async;
4435
45- $loop = Factory::create();
46- $eventLoopBridge = new EventLoopBridge($loop);
36+ $eventLoopBridge = new EventLoopBridge();
4737
48- $channel = new Channel(Channel::Infinite);
49- $eventLoopBridge->observe($channel)->subscribe(function (string $message) {
50- echo $message, PHP_EOL;
51- });
38+ Loop::futureTick(async(static function () use ($eventLoopBridge) {
39+ /** @var Channel<string > */
40+ $channel = new Channel(Channel::Infinite);
5241
53- $loop-> futureTick(function () use ($channel): void {
54- $channel->send('Hello World!');
55- $channel->close();
56- });
42+ Loop:: futureTick(function () use ($channel): void {
43+ $channel->send('Hello World!');
44+ $channel->close();
45+ });
5746
58- $loop->run();
47+ foreach ($eventLoopBridge->observe($channel) as $message) {
48+ echo $message, PHP_EOL;
49+ }
50+ }));
5951```
6052
6153## Futures
@@ -64,24 +56,20 @@ Where promises are push, futures are pull, as such the event loop will poll and
6456available.
6557
6658``` php
67- use parallel\Channel;
68- use React\EventLoop\Factory;
59+ use React\EventLoop\Loop;
6960use ReactParallel\EventLoop\EventLoopBridge;
7061use function parallel\run;
62+ use function React\Async\async;
7163
72- $loop = Factory::create();
73- $eventLoopBridge = new EventLoopBridge($loop);
74-
75- $future = run(function (): string {
76- return 'Hello World!';
77- });
64+ $eventLoopBridge = new EventLoopBridge();
7865
79- $channel = new Channel(Channel::Infinite);
80- $eventLoopBridge->await($ future)->then (function (string $message) {
81- echo $message, PHP_EOL ;
82- });
66+ Loop::futureTick(async(static function () use ($eventLoopBridge) {
67+ $ future = run (function (): string {
68+ return 'Hello World!' ;
69+ });
8370
84- $loop->run();
71+ echo $eventLoopBridge->await($future), PHP_EOL;
72+ }));
8573```
8674
8775## Metrics
@@ -105,7 +93,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
10593
10694## License ##
10795
108- Copyright 2024 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
96+ Copyright 2025 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
10997
11098Permission is hereby granted, free of charge, to any person
11199obtaining a copy of this software and associated documentation
0 commit comments