From ae93b4cf2123f5a9bb3081c3d5e7389ed7f866c3 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sun, 27 Dec 2020 16:31:45 -0600 Subject: [PATCH] Rename Signal to SignalTrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also renamed Amp\signal() to trap(), a nice analog to bash’s trap. --- lib/{Signal.php => SignalTrap.php} | 2 +- lib/functions.php | 2 +- test/{SignalTest.php => SignalTrapTest.php} | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) rename lib/{Signal.php => SignalTrap.php} (97%) rename test/{SignalTest.php => SignalTrapTest.php} (61%) diff --git a/lib/Signal.php b/lib/SignalTrap.php similarity index 97% rename from lib/Signal.php rename to lib/SignalTrap.php index 29004bd..1f0d3b7 100644 --- a/lib/Signal.php +++ b/lib/SignalTrap.php @@ -2,7 +2,7 @@ namespace Amp; -final class Signal implements Promise +final class SignalTrap implements Promise { private Internal\Placeholder $placeholder; diff --git a/lib/functions.php b/lib/functions.php index 08a9938..d031f07 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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; diff --git a/test/SignalTest.php b/test/SignalTrapTest.php similarity index 61% rename from test/SignalTest.php rename to test/SignalTrapTest.php index d0d0713..4ce8938 100644 --- a/test/SignalTest.php +++ b/test/SignalTrapTest.php @@ -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); + } }