@@ -23,39 +23,31 @@ event loop, that will work, but it adds additional overhead when you have more t
23
23
different major contexts. Share this bridge around so that other packages can use them, and only have one instance
24
24
checking for events.
25
25
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
-
36
26
## Channels
37
27
38
28
Channels often have a stream of messages going over them, as such the bridge will convert them into an observable.
39
29
40
30
``` php
41
31
use parallel\Channel;
42
- use React\EventLoop\Factory ;
32
+ use React\EventLoop\Loop ;
43
33
use ReactParallel\EventLoop\EventLoopBridge;
34
+ use function React\Async\async;
44
35
45
- $loop = Factory::create();
46
- $eventLoopBridge = new EventLoopBridge($loop);
36
+ $eventLoopBridge = new EventLoopBridge();
47
37
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);
52
41
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
+ });
57
46
58
- $loop->run();
47
+ foreach ($eventLoopBridge->observe($channel) as $message) {
48
+ echo $message, PHP_EOL;
49
+ }
50
+ }));
59
51
```
60
52
61
53
## Futures
@@ -64,24 +56,20 @@ Where promises are push, futures are pull, as such the event loop will poll and
64
56
available.
65
57
66
58
``` php
67
- use parallel\Channel;
68
- use React\EventLoop\Factory;
59
+ use React\EventLoop\Loop;
69
60
use ReactParallel\EventLoop\EventLoopBridge;
70
61
use function parallel\run;
62
+ use function React\Async\async;
71
63
72
- $loop = Factory::create();
73
- $eventLoopBridge = new EventLoopBridge($loop);
74
-
75
- $future = run(function (): string {
76
- return 'Hello World!';
77
- });
64
+ $eventLoopBridge = new EventLoopBridge();
78
65
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
+ });
83
70
84
- $loop->run();
71
+ echo $eventLoopBridge->await($future), PHP_EOL;
72
+ }));
85
73
```
86
74
87
75
## Metrics
@@ -105,7 +93,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
105
93
106
94
## License ##
107
95
108
- Copyright 2024 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
96
+ Copyright 2025 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
109
97
110
98
Permission is hereby granted, free of charge, to any person
111
99
obtaining a copy of this software and associated documentation
0 commit comments