1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00

Rename Signal to SignalTrap

Also renamed Amp\signal() to trap(), a nice analog to bash’s trap.
This commit is contained in:
Aaron Piotrowski 2020-12-27 16:31:45 -06:00
parent 80ea42bdcf
commit ae93b4cf21
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 17 additions and 7 deletions

View File

@ -2,7 +2,7 @@
namespace Amp;
final class Signal implements Promise
final class SignalTrap implements Promise
{
private Internal\Placeholder $placeholder;

View File

@ -237,7 +237,7 @@ namespace Amp
*
* @return int The signal number received.
*/
function signal(int $signal, int ...$signals): int
function trap(int $signal, int ...$signals): int
{
$signals[] = $signal;

View File

@ -4,25 +4,26 @@ namespace Amp\Test;
use Amp\Loop;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Signal;
use Amp\SignalTrap;
use function Amp\await;
use function Amp\trap;
/**
* @requires ext-pcntl
*/
class SignalTest extends AsyncTestCase
class SignalTrapTest extends AsyncTestCase
{
public function testDelayed(): void
{
$this->setMinimumRuntime(20);
$promise = new Signal(\SIGUSR1, \SIGUSR2);
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
$this->assertSame(\SIGUSR1, await($promise));
$promise = new Signal(\SIGUSR1, \SIGUSR2);
$promise = new SignalTrap(\SIGUSR1, \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));
$promise = new Signal(\SIGUSR1, \SIGUSR2);
$promise = new SignalTrap(\SIGUSR1, \SIGUSR2);
$promise->unreference();
$promise->reference();
await($promise);
}
public function testTrapFunction(): void
{
$this->setMinimumRuntime(10);
Loop::delay(10, fn() => \posix_kill(\getmypid(), \SIGUSR1));
trap(\SIGUSR1, \SIGUSR2);
}
}