Skip to content

Commit 9990aa8

Browse files
committed
% refactoring catch_or_cancel logic according to RFC scope behavior
1 parent 7b665ed commit 9990aa8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Zend/zend_async_API.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,8 @@ zend_async_callbacks_notify(zend_async_event_t *event, void *result, zend_object
10551055
{
10561056
// Protect from self-deletion by incrementing ref count before calling callbacks
10571057
ZEND_ASYNC_EVENT_ADD_REF(event);
1058+
// Automatically clear exception handled flag
1059+
ZEND_ASYNC_EVENT_CLR_EXCEPTION_HANDLED(event);
10581060

10591061
// If pre-notify returns false, we stop notifying callbacks
10601062
if (false == from_handler && event->notify_handler != NULL) {

Zend/zend_async_API.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,24 @@ struct _zend_async_scope_s {
654654

655655
zend_async_before_coroutine_enqueue_t before_coroutine_enqueue;
656656
zend_async_after_coroutine_enqueue_t after_coroutine_enqueue;
657-
void (*cancel)(zend_async_scope_t *scope, zend_object *error, bool transfer_error, const bool is_safely);
657+
658+
/**
659+
* The method handles an exception delivered to the Scope.
660+
* Its result may either be the cancellation of the Scope or the suppression of the exception.
661+
* If the coroutine parameter is specified, it indicates an attempt to handle an exception from a coroutine.
662+
* Otherwise, it's an attempt by the user to stop the execution of the Scope.
663+
*
664+
* The method should return true if the exception was handled and the Scope can continue execution.
665+
*
666+
* This method is the central point of responsibility where the behavior in case of an error is determined.
667+
*/
668+
bool (*catch_or_cancel)(
669+
zend_async_scope_t *scope,
670+
zend_coroutine_t *coroutine,
671+
zend_object *exception,
672+
bool transfer_error,
673+
const bool is_safely
674+
);
658675
};
659676

660677
#define ZEND_ASYNC_SCOPE_F_CLOSED ZEND_ASYNC_EVENT_F_CLOSED /* scope was closed */

0 commit comments

Comments
 (0)