Skip to content

Implementations of ::run() use signals->isEmpty() which prevents exiting #218

@idimsh

Description

@idimsh

In all implementations of \React\EventLoop\LoopInterface::run

$this->signals->isEmpty()

is part of the conditions to check if there is something else to do.
This is not really correct, the loop after executing all the added Timers is waiting for a the signals registered to response to and make

$nothingLeftToDo

become true.
It is not really required to wait for the signal, what if the signal is not received? The loop run() keep going until it is either stop() or all the registered signals have been triggered.

Registering signals should mean: what to do if this signal received, and not that registered signals have to be received.

sample

<?php
declare(strict_types=1);
require_once '../../vendor/autoload.php';

$loop = \React\EventLoop\Factory::create();

$loop->addTimer(
    0.01,
    function () use ($loop) {
        $loop->addSignal(
            SIGUSR1,
            function (int $signal) {
                fputs(STDOUT, "signal [$signal] received\n");
            }
        );
        fputs(STDOUT, "in first callback\n");
    }
);
$loop->addSignal(
    SIGINT,
    function (int $signal) {
        fputs(STDOUT, "signal [$signal] received\n");
    }
);

fputs(STDOUT, "Now it will keep waiting for SIGUSR1 && for SIGINT, clicking Ctrl-c will not end the process \n");
$loop->run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions