Skip to content

delay() should throw a custom exception, implement throwIfCanceled() #93

Description

@appkit-framework

Hello,

I believe it would be more appropriate for delay() to throw a custom exception specific to cancellation (e.g., CanceledException) instead of a standard PHP's \RuntimeException.
This would allow developers to more easily distinguish between expected cancellations and other unexpected errors.

Additionally, it would be great if ReactPHP could provide a helper function, like this one:

function throwIfCanceled() {
    await(new Promise(
        function($resolve) {
            $resolve(null);
        },
        function() {
            throw new CanceledException();
        }
    ));
}

This would allow developers to handle the cancellation of asynchronous tasks at specific points in the code, such as after each iteration of a long-running loop (essentially the same as delay(0)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions