File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+ /**
5
+ * This file is part of Hyperf.
6
+ *
7
+ * @link https://www.hyperf.io
8
+ * @document https://hyperf.wiki
9
+ * @contact group@hyperf.io
10
+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11
+ */
12
+
13
+ namespace Hyperf \Coroutine ;
14
+
15
+ /**
16
+ * @method bool isFull()
17
+ * @method bool isEmpty()
18
+ */
19
+ class WaitConcurrent extends Concurrent
20
+ {
21
+ protected WaitGroup $ wg ;
22
+
23
+ public function __construct (protected int $ limit )
24
+ {
25
+ parent ::__construct ($ limit );
26
+ $ this ->wg = new WaitGroup ();
27
+ }
28
+
29
+ public function create (callable $ callable ): void
30
+ {
31
+ $ this ->wg ->add ();
32
+
33
+ $ callable = function () use ($ callable ) {
34
+ try {
35
+ $ callable ();
36
+ } finally {
37
+ $ this ->wg ->done ();
38
+ }
39
+ };
40
+
41
+ parent ::create ($ callable );
42
+ }
43
+
44
+ public function wait (float $ timeout = -1 ): bool
45
+ {
46
+ return $ this ->wg ->wait ($ timeout );
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments