From 2d9f8dd10f7febea439ba8b4b96d1ab06f9d1595 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 27 Feb 2023 10:03:40 +0100 Subject: [PATCH 1/3] composer.json: Suggest to install PHP `ev` --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 920348c..7b18ff6 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,9 @@ "simshaun/recurr": "^5", "ipl/stdlib": ">=0.12.0" }, + "suggest": { + "ext-ev": "Improves performance, efficiency and avoids system limitations. Highly recommended! (See https://www.php.net/manual/en/intro.ev.php for details)" + }, "autoload": { "files": ["src/register_cron_aliases.php"], "psr-4": { From f657d0654638b8b4f79df3029e1a97f8ab7bb886 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 27 Feb 2023 10:21:43 +0100 Subject: [PATCH 2/3] workflows: Setup PHP with `ev` extension --- .github/workflows/php.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index cce59a8..77d798b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -27,6 +27,7 @@ jobs: with: php-version: ${{ matrix.php }} tools: phpcs + extensions: ev - name: Setup dependencies run: composer require -n --no-progress overtrue/phplint @@ -61,6 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} tools: phpunit:${{ env.PHPUNIT_VERSION }} + extensions: ev - name: Setup dependencies run: composer install -n --no-progress From 9f2e988dcf774f17462f32a65f4e003ccca8efcd Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 27 Feb 2023 10:17:43 +0100 Subject: [PATCH 3/3] tests: Fix canceling running tasks --- tests/SchedulerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/SchedulerTest.php b/tests/SchedulerTest.php index a6af0bf..cd85809 100644 --- a/tests/SchedulerTest.php +++ b/tests/SchedulerTest.php @@ -114,14 +114,14 @@ function (Task $_, array $promises) use (&$canceledPromises): void { } ); - // Tick callbacks are guaranteed to be executed in the order they are enqueued, - // thus we will not be able to remove the task before it is finished. Therefore, - // we need to use timers with 0 intervals. - Loop::addTimer(0, function () use ($task): void { + // Wait .001ms for the scheduler to run the task at least 2x before removing it und stopping the event loop. + Loop::addTimer(.001, function () use ($task): void { $this->scheduler->remove($task); + + Loop::stop(); }); - $this->runAndStopEventLoop(); + Loop::run(); // When a task is due before the ongoing promise gets resolved, the scheduler will // not cancel it. Instead, it will start a new one for the new operations.