File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ namespace Hyperf \Engine \Contract ;
13+
14+ interface SignalInterface
15+ {
16+ public static function wait (int $ signo , float $ timeout = -1 ): bool ;
17+ }
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+ namespace Hyperf \Engine ;
13+
14+ use Hyperf \Engine \Contract \SignalInterface ;
15+ use Swoole \Coroutine \System ;
16+
17+ class Signal implements SignalInterface
18+ {
19+ public static function wait (int $ signo , float $ timeout = -1 ): bool
20+ {
21+ return System::waitSignal ($ signo , $ timeout );
22+ }
23+ }
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+ namespace HyperfTest \Cases ;
13+
14+ use Hyperf \Engine \Signal ;
15+
16+ /**
17+ * @internal
18+ * @coversNothing
19+ */
20+ class SignalTest extends AbstractTestCase
21+ {
22+ public function testSignal ()
23+ {
24+ $ this ->runInCoroutine (function () {
25+ $ res = Signal::wait (SIGUSR1 , 1 );
26+ $ this ->assertFalse ($ res );
27+
28+ go (static function () {
29+ sleep (1 );
30+ posix_kill (getmypid (), SIGUSR1 );
31+ });
32+
33+ $ res = Signal::wait (SIGUSR1 , 2 );
34+ $ this ->assertTrue ($ res );
35+ });
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments