mirror of
https://github.com/danog/amp.git
synced 2025-01-22 21:31:18 +01:00
Rename Signal to SignalTrap
Also renamed Amp\signal() to trap(), a nice analog to bash’s trap.
This commit is contained in:
parent
80ea42bdcf
commit
ae93b4cf21
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Amp;
|
namespace Amp;
|
||||||
|
|
||||||
final class Signal implements Promise
|
final class SignalTrap implements Promise
|
||||||
{
|
{
|
||||||
private Internal\Placeholder $placeholder;
|
private Internal\Placeholder $placeholder;
|
||||||
|
|
@ -237,7 +237,7 @@ namespace Amp
|
|||||||
*
|
*
|
||||||
* @return int The signal number received.
|
* @return int The signal number received.
|
||||||
*/
|
*/
|
||||||
function signal(int $signal, int ...$signals): int
|
function trap(int $signal, int ...$signals): int
|
||||||
{
|
{
|
||||||
$signals[] = $signal;
|
$signals[] = $signal;
|
||||||
|
|
||||||
|
@ -4,25 +4,26 @@ namespace Amp\Test;
|
|||||||
|
|
||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
use Amp\PHPUnit\AsyncTestCase;
|
use Amp\PHPUnit\AsyncTestCase;
|
||||||
use Amp\Signal;
|
use Amp\SignalTrap;
|
||||||
use function Amp\await;
|
use function Amp\await;
|
||||||
|
use function Amp\trap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires ext-pcntl
|
* @requires ext-pcntl
|
||||||
*/
|
*/
|
||||||
class SignalTest extends AsyncTestCase
|
class SignalTrapTest extends AsyncTestCase
|
||||||
{
|
{
|
||||||
public function testDelayed(): void
|
public function testDelayed(): void
|
||||||
{
|
{
|
||||||
$this->setMinimumRuntime(20);
|
$this->setMinimumRuntime(20);
|
||||||
|
|
||||||
$promise = new Signal(\SIGUSR1, \SIGUSR2);
|
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
|
||||||
|
|
||||||
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
|
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
|
||||||
|
|
||||||
$this->assertSame(\SIGUSR1, await($promise));
|
$this->assertSame(\SIGUSR1, await($promise));
|
||||||
|
|
||||||
$promise = new Signal(\SIGUSR1, \SIGUSR2);
|
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
|
||||||
|
|
||||||
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR2));
|
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR2));
|
||||||
|
|
||||||
@ -35,10 +36,19 @@ class SignalTest extends AsyncTestCase
|
|||||||
|
|
||||||
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
|
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
|
||||||
|
|
||||||
$promise = new Signal(\SIGUSR1, \SIGUSR2);
|
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
|
||||||
$promise->unreference();
|
$promise->unreference();
|
||||||
$promise->reference();
|
$promise->reference();
|
||||||
|
|
||||||
await($promise);
|
await($promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTrapFunction(): void
|
||||||
|
{
|
||||||
|
$this->setMinimumRuntime(10);
|
||||||
|
|
||||||
|
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
|
||||||
|
|
||||||
|
trap(\SIGUSR1, \SIGUSR2);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user