Skip to content

Commit

Permalink
tests: Fix canceling running tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Mar 1, 2023
1 parent f657d06 commit 9f2e988
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9f2e988

Please sign in to comment.