Skip to content

Commit

Permalink
remove dispatch mode in SignalRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
marie committed Oct 1, 2019
1 parent 42fe664 commit 0118e9c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 40 deletions.
11 changes: 2 additions & 9 deletions src/Symfony/Component/SignalRegistry/SignalRegistry.php
Expand Up @@ -6,11 +6,9 @@ final class SignalRegistry implements SignalRegistryInterface
{
private $signals = [];

public function __construct(bool $asynchronousMode = true)
public function __construct()
{
if ($asynchronousMode) {
pcntl_async_signals(true);
}
pcntl_async_signals(true);
}

public function register(int $signal, callable $callback): void
Expand All @@ -19,11 +17,6 @@ public function register(int $signal, callable $callback): void
pcntl_signal($signal, [$this, 'handler']);
}

public function dispatch(): bool
{
return pcntl_signal_dispatch();
}

public function handler(int $signal): void
{
foreach($this->signals[$signal] as $callback) {
Expand Down
Expand Up @@ -4,8 +4,7 @@

interface SignalRegistryInterface
{
public function __construct(bool $asynchronousMode = true);
public function __construct();
public function register(int $signal, callable $callback): void;
public function dispatch(): bool;
public function handler(int $signal): void;
}
32 changes: 3 additions & 29 deletions src/Symfony/Component/SignalRegistry/Tests/SignalRegistryTest.php
Expand Up @@ -3,6 +3,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\SignalRegistry\SignalRegistry;

/**
* @requires extension pcntl
*/
class SignalRegistryTest extends TestCase
{
public function tearDown(): void
Expand Down Expand Up @@ -70,33 +73,4 @@ public function testTwoSignals_AsyncMode_signalsAreHandled()

$this->assertTrue($isHandled2);
}

public function testOneCallbackForASignal_DispatchMode_signalIsNotHandled()
{
$signalRegistry = new SignalRegistry(false);

$isHandled = false;
$signalRegistry->register(SIGUSR1, function() use (&$isHandled) {
$isHandled = true;
});

posix_kill(posix_getpid(), SIGUSR1);

$this->assertFalse($isHandled);
}

public function testOneCallbackForASignal_DispatchMode_signalIsHandled()
{
$signalRegistry = new SignalRegistry(false);

$isHandled = false;
$signalRegistry->register(SIGUSR1, function() use (&$isHandled) {
$isHandled = true;
});

posix_kill(posix_getpid(), SIGUSR1);
$signalRegistry->dispatch();

$this->assertTrue($isHandled);
}
}

0 comments on commit 0118e9c

Please sign in to comment.