Skip to content

Conversation

@stevebauman
Copy link
Member

@stevebauman stevebauman commented Sep 9, 2025

Closes #97

This PR adds the ability to break out of mailbox idle by supplying a callback into the timeout parameter.

A timeout callback is called for each iteration of the idle loop, allowing it to effectively break out of it.

  • Returning false from the callback will result in the idle cancelled.
  • Returning a number from the callback will result in the number being used as the timeout for the upcoming idle.
$loop = 0;

$mailbox->inbox()->idle(
    callback: function (Message $message) {
        // ...
    },
    timeout: function () use (&$loop) {
        if ($loop > 5) {
            return false; // break after 5 IDLE's
        }

        try {
            return 100; // timeout in seconds
        } finally {
            $loop++;
        }
    }
);

@stevebauman stevebauman mentioned this pull request Sep 9, 2025
@stevebauman stevebauman merged commit e1abaf0 into master Sep 9, 2025
13 checks passed
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.

How to stop IDLE?

2 participants