File tree Expand file tree Collapse file tree 3 files changed +72
-2
lines changed
Expand file tree Collapse file tree 3 files changed +72
-2
lines changed Original file line number Diff line number Diff line change 2424 },
2525 "require" : {
2626 "php" : " >=8.0" ,
27- "hyperf/engine-contract" : " ~1.12 .0"
27+ "hyperf/engine-contract" : " ~1.13 .0"
2828 },
2929 "require-dev" : {
3030 "friendsofphp/php-cs-fixer" : " ^3.0" ,
5252 },
5353 "extra" : {
5454 "branch-alias" : {
55- "dev-master" : " 2.13 -dev"
55+ "dev-master" : " 2.14 -dev"
5656 },
5757 "hyperf" : {
5858 "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+ * @contact group@hyperf.io
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 Swoole \Coroutine \Barrier as SwooleBarrier ;
17+
18+ class Barrier implements BarrierInterface
19+ {
20+ public static function wait (object &$ barrier , int $ timeout = -1 ): void
21+ {
22+ SwooleBarrier::wait ($ barrier , $ timeout );
23+ }
24+
25+ public static function create (): object
26+ {
27+ return SwooleBarrier::make ();
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+ * @contact group@hyperf.io
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+ $ this ->runInCoroutine (function () {
27+ $ barrier = Barrier::create ();
28+ $ N = 10 ;
29+ $ count = 0 ;
30+ for ($ i = 0 ; $ i < $ N ; ++$ i ) {
31+ Coroutine::create (function () use (&$ count , $ barrier ) {
32+ isset ($ barrier );
33+ usleep (2000 );
34+ ++$ count ;
35+ });
36+ }
37+ Barrier::wait ($ barrier );
38+ $ this ->assertSame ($ N , $ count );
39+ });
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments