File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,14 @@ public function send($message): Generator;
4343 *
4444 * This function is used to receive a message from the channel.
4545 */
46- public function receive (): Generator ;
46+ public function receiveGen (): Generator ;
47+
48+ /**
49+ * @return mixed
50+ *
51+ * This function is used to receive a message from the channel.
52+ */
53+ public function receive (): mixed ;
4754
4855 /**
4956 * @return bool
@@ -89,7 +96,7 @@ public function send($message): Generator
8996 $ this ->locked = false ;
9097 }
9198
92- public function receive (): Generator
99+ public function receiveGen (): Generator
93100 {
94101 $ this ->exceptionIfClosed ();
95102 while ($ this ->locked ) {
@@ -102,6 +109,18 @@ public function receive(): Generator
102109 return yield $ message ;
103110 }
104111
112+ public function receive (): mixed
113+ {
114+ $ this ->exceptionIfClosed ();
115+ while ($ this ->locked ) {
116+ CoroutineGen::run ();
117+ }
118+ $ this ->locked = true ;
119+ $ message = array_shift ($ this ->queue );
120+ $ this ->locked = false ;
121+ return $ message ;
122+ }
123+
105124 public function isEmpty (): bool
106125 {
107126 return empty ($ this ->queue );
@@ -122,4 +141,4 @@ private function exceptionIfClosed(): void
122141 if ($ this ->closed ) throw new RuntimeException ('Channel is closed ' );
123142 }
124143
125- }
144+ }
You can’t perform that action at this time.
0 commit comments