File tree 3 files changed +71
-3
lines changed
3 files changed +71
-3
lines changed Original file line number Diff line number Diff line change 21
21
}
22
22
},
23
23
"replace" : {
24
- "hyperf/engine" : " ~2.13 .0"
24
+ "hyperf/engine" : " ~2.14 .0"
25
25
},
26
26
"require" : {
27
27
"php" : " >=8.0" ,
28
- "hyperf/engine-contract" : " ~1.12 .0" ,
28
+ "hyperf/engine-contract" : " ~1.13 .0" ,
29
29
"swow/swow" : " ^1.0"
30
30
},
31
31
"require-dev" : {
51
51
},
52
52
"extra" : {
53
53
"branch-alias" : {
54
- "dev-master" : " 2.13 -dev"
54
+ "dev-master" : " 2.14 -dev"
55
55
},
56
56
"hyperf" : {
57
57
"config" : " Hyperf\\ Engine\\ ConfigProvider"
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
+
10
+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11
+ */
12
+
13
+ namespace Hyperf \Engine ;
14
+
15
+ use Hyperf \Engine \Contract \BarrierInterface ;
16
+ use Swow \Sync \WaitReference ;
17
+
18
+ class Barrier implements BarrierInterface
19
+ {
20
+ public static function wait (object &$ barrier , int $ timeout = -1 ): void
21
+ {
22
+ WaitReference::wait ($ barrier , $ timeout );
23
+ }
24
+
25
+ public static function create (): object
26
+ {
27
+ return new WaitReference ();
28
+ }
29
+ }
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
+
10
+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11
+ */
12
+
13
+ namespace HyperfTest \Cases ;
14
+
15
+ use Hyperf \Engine \Barrier ;
16
+ use Hyperf \Engine \Coroutine ;
17
+
18
+ /**
19
+ * @internal
20
+ * @coversNothing
21
+ */
22
+ class BarrierTest extends AbstractTestCase
23
+ {
24
+ public function testBarrier ()
25
+ {
26
+ $ barrier = Barrier::create ();
27
+ $ N = 10 ;
28
+ $ count = 0 ;
29
+ for ($ i = 0 ; $ i < $ N ; ++$ i ) {
30
+ Coroutine::create (function () use (&$ count , $ barrier ) {
31
+ isset ($ barrier );
32
+ usleep (2000 );
33
+ ++$ count ;
34
+ });
35
+ }
36
+ Barrier::wait ($ barrier );
37
+ $ this ->assertSame ($ N , $ count );
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments