Optimized `Hyperf\Coordinator\Timer::tick()` to run the callback inside `Hyperf\Coroutine\wait()` so it executes in a properly managed coroutine context. by huangdijia · Pull Request #7761 · hyperf/hyperf · GitHub
Skip to content

Optimized Hyperf\Coordinator\Timer::tick() to run the callback inside Hyperf\Coroutine\wait() so it executes in a properly managed coroutine context.#7761

Merged
limingxinleo merged 7 commits into
hyperf:3.1from
huangdijia:fix-timer-wait-3.1
Jun 15, 2026

Conversation

@huangdijia

Copy link
Copy Markdown
Member

Why

The Timer callback was invoked directly inside the timer coroutine. Wrapping it with Hyperf\Coroutine\wait() ensures the callback runs in a properly managed coroutine context.

What

  • Wrap $closure($isClosing) with wait(fn() => $closure($isClosing)) in Timer::tick().
  • Move $round = 0 initialization out of the try block.
  • Import Hyperf\Coroutine\wait.

Run the timer callback inside Hyperf\Coroutine\wait() so it executes in a
properly managed coroutine context, and move the $round initialization
outside the try block.
@huangdijia huangdijia force-pushed the fix-timer-wait-3.1 branch from 12a0b9d to e83a40f Compare June 15, 2026 06:46
@huangdijia huangdijia requested a review from limingxinleo June 15, 2026 06:50
@limingxinleo limingxinleo changed the title Wrap timer closure execution with coroutine wait() Optimized Hyperf\Coordinator\Timer::tick() to run the callback inside Hyperf\Coroutine\wait() so it executes in a properly managed coroutine context. Jun 15, 2026
@limingxinleo limingxinleo merged commit 580897a into hyperf:3.1 Jun 15, 2026
79 of 80 checks passed
@huangdijia huangdijia deleted the fix-timer-wait-3.1 branch June 15, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants