1010use React \EventLoop \Loop ;
1111use React \EventLoop \TimerInterface ;
1212use React \Promise \Deferred ;
13- use Rx \Subject \Subject ;
1413use WyriHaximus \Metrics \Label ;
1514
1615use function count ;
1716use function React \Async \await ;
1817use function spl_object_hash ;
1918use function spl_object_id ;
20- use function WyriHaximus \React \awaitObservable ;
2119
2220use const WyriHaximus \Constants \Numeric \ZERO ;
2321
@@ -40,7 +38,7 @@ final class EventLoopBridge
4038
4139 private TimerInterface |null $ timer = null ;
4240
43- /** @var array<int, Subject > */
41+ /** @var array<int, Stream > */
4442 private array $ channels = [];
4543
4644 /** @var array<int, Deferred> */
@@ -68,8 +66,7 @@ public function withMetrics(Metrics $metrics): self
6866 /** @return iterable<mixed> */
6967 public function observe (Channel $ channel ): iterable
7068 {
71- $ subject = new Subject ();
72- $ this ->channels [spl_object_id ($ channel )] = $ subject ;
69+ $ this ->channels [spl_object_id ($ channel )] = new Stream ();
7370 $ this ->events ->addChannel ($ channel );
7471
7572 if ($ this ->metrics instanceof Metrics) {
@@ -78,7 +75,7 @@ public function observe(Channel $channel): iterable
7875
7976 $ this ->startTimer ();
8077
81- return awaitObservable ( $ subject );
78+ yield from $ this -> channels [ spl_object_id ( $ channel )]-> iterable ( );
8279 }
8380
8481 public function await (Future $ future ): mixed
@@ -228,7 +225,7 @@ private function handleFutureReadEvent(Events\Event $event): void
228225
229226 private function handleChannelReadEvent (Events \Event $ event ): void
230227 {
231- $ this ->channels [spl_object_id ($ event ->object )]->onNext ($ event ->value );
228+ $ this ->channels [spl_object_id ($ event ->object )]->value ($ event ->value );
232229 $ this ->events ->addChannel ($ event ->object ); /** @phpstan-ignore-line */
233230
234231 if (! ($ this ->metrics instanceof Metrics)) {
@@ -240,7 +237,7 @@ private function handleChannelReadEvent(Events\Event $event): void
240237
241238 private function handleCloseEvent (Events \Event $ event ): void
242239 {
243- $ this ->channels [spl_object_id ($ event ->object )]->onCompleted ();
240+ $ this ->channels [spl_object_id ($ event ->object )]->done ();
244241 unset($ this ->channels [spl_object_id ($ event ->object )]);
245242
246243 if (! ($ this ->metrics instanceof Metrics)) {
0 commit comments