11<?php
22
3- namespace Voryx \React \EventLoop ;
3+ namespace Voryx \React \AsyncInterop ;
44
5- use Interop \Async \Loop ;
5+ use Interop \Async \Loop as InteropLoop ;
66use React \EventLoop \LoopInterface ;
77use React \EventLoop \Timer \TimerInterface ;
88
9- class ReactAsyncInteropLoop implements LoopInterface
9+ final class Loop implements LoopInterface
1010{
1111 private $ readStreams = [];
1212 private $ writeStreams = [];
@@ -17,7 +17,7 @@ public function addReadStream($stream, callable $listener)
1717 if (isset ($ this ->readStreams [$ key ])) {
1818 throw new \Exception ('key set twice ' );
1919 }
20- $ this ->readStreams [$ key ] = Loop ::get ()->onReadable ($ stream , function () use ($ listener , $ stream ) {
20+ $ this ->readStreams [$ key ] = InteropLoop ::get ()->onReadable ($ stream , function () use ($ listener , $ stream ) {
2121 $ listener ($ stream );
2222 });
2323 }
@@ -30,7 +30,7 @@ public function addWriteStream($stream, callable $listener)
3030 throw new \Exception ('key set twice ' );
3131 }
3232
33- $ this ->writeStreams [$ key ] = Loop ::get ()->onWritable ($ stream , function () use ($ listener , $ stream ) {
33+ $ this ->writeStreams [$ key ] = InteropLoop ::get ()->onWritable ($ stream , function () use ($ listener , $ stream ) {
3434 $ listener ($ stream );
3535 });
3636 }
@@ -39,7 +39,7 @@ public function removeReadStream($stream)
3939 {
4040 $ key = (int )$ stream ;
4141 if (isset ($ this ->readStreams [$ key ])) {
42- Loop ::get ()->cancel ($ this ->readStreams [$ key ]);
42+ InteropLoop ::get ()->cancel ($ this ->readStreams [$ key ]);
4343 unset($ this ->readStreams [$ key ]);
4444 }
4545 }
@@ -48,7 +48,7 @@ public function removeWriteStream($stream)
4848 {
4949 $ key = (int )$ stream ;
5050 if (isset ($ this ->writeStreams [$ key ])) {
51- Loop ::get ()->cancel ($ this ->writeStreams [$ key ]);
51+ InteropLoop ::get ()->cancel ($ this ->writeStreams [$ key ]);
5252 unset($ this ->writeStreams [$ key ]);
5353 }
5454 }
@@ -66,11 +66,11 @@ private function addWrappedTimer($interval, callable $callback, $isPeriodic = fa
6666 };
6767 $ millis = $ interval * 1000 ;
6868 if ($ isPeriodic ) {
69- $ timerKey = Loop ::get ()->repeat ($ millis , $ wrappedCallback );
69+ $ timerKey = InteropLoop ::get ()->repeat ($ millis , $ wrappedCallback );
7070 } else {
71- $ timerKey = Loop ::get ()->delay ($ millis , $ wrappedCallback );
71+ $ timerKey = InteropLoop ::get ()->delay ($ millis , $ wrappedCallback );
7272 }
73- $ timer = new ReactAsyncInteropTimer (
73+ $ timer = new Timer (
7474 $ timerKey ,
7575 $ interval ,
7676 $ callback ,
@@ -102,7 +102,7 @@ public function isTimerActive(TimerInterface $timer)
102102
103103 public function nextTick (callable $ listener )
104104 {
105- Loop ::get ()->defer (function () use ($ listener ) {
105+ InteropLoop ::get ()->defer (function () use ($ listener ) {
106106 $ listener ($ this );
107107 });
108108 }
@@ -114,7 +114,7 @@ public function futureTick(callable $listener)
114114
115115 public function tick ()
116116 {
117- $ loop = Loop ::get ();
117+ $ loop = InteropLoop ::get ();
118118
119119 $ loop ->defer (function () use ($ loop ) {
120120 $ loop ->stop ();
@@ -125,11 +125,11 @@ public function tick()
125125
126126 public function run ()
127127 {
128- Loop ::get ()->run ();
128+ InteropLoop ::get ()->run ();
129129 }
130130
131131 public function stop ()
132132 {
133- Loop ::get ()->stop ();
133+ InteropLoop ::get ()->stop ();
134134 }
135135}
0 commit comments