Skip to content

Commit 8ee66aa

Browse files
committed
+ ZEND_ASYNC_WAKER_APPLY_ERROR
1 parent cbe111c commit 8ee66aa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Zend/zend_async_API.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,32 @@ ZEND_API zend_async_waker_t * zend_async_waker_new_with_timeout(
711711
return waker;
712712
}
713713

714+
ZEND_API bool zend_async_waker_apply_error(zend_async_waker_t *waker, zend_object *error, bool override, bool for_cancellation)
715+
{
716+
if (UNEXPECTED(waker == NULL)) {
717+
return false;
718+
}
719+
720+
if (EXPECTED(waker->error == NULL)) {
721+
waker->error = error;
722+
return true;
723+
}
724+
725+
if (for_cancellation && instanceof_function(waker->error->ce, zend_ce_cancellation_exception)) {
726+
// If the waker already has a cancellation exception, we do not override it
727+
return false;
728+
}
729+
730+
if (override) {
731+
zend_exception_set_previous(error, waker->error);
732+
waker->error = error;
733+
} else {
734+
zend_exception_set_previous(waker->error, error);
735+
}
736+
737+
return true;
738+
}
739+
714740
//////////////////////////////////////////////////////////////////////
715741
/* Waker API end */
716742
//////////////////////////////////////////////////////////////////////

Zend/zend_async_API.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,14 @@ ZEND_API zend_async_waker_t *zend_async_waker_new(zend_coroutine_t *coroutine);
11241124
ZEND_API zend_async_waker_t * zend_async_waker_new_with_timeout(
11251125
zend_coroutine_t * coroutine, const zend_ulong timeout, zend_async_event_t *cancellation
11261126
);
1127+
ZEND_API bool zend_async_waker_apply_error(zend_async_waker_t *waker, zend_object *error, bool override, bool for_cancellation);
11271128
ZEND_API void zend_async_waker_destroy(zend_coroutine_t *coroutine);
11281129
ZEND_API void zend_async_waker_add_triggered_event(zend_coroutine_t *coroutine, zend_async_event_t *event);
11291130

1131+
#define ZEND_ASYNC_WAKER_APPLY_ERROR(waker, error) zend_async_waker_apply_error((waker), (error), true, false)
1132+
#define ZEND_ASYNC_WAKER_APPEND_ERROR(waker, error) zend_async_waker_apply_error((waker), (error), false, false)
1133+
#define ZEND_ASYNC_WAKER_APPLY_CANCELLATION(waker, error) zend_async_waker_apply_error((waker), (error), true, true)
1134+
11301135
ZEND_API void zend_async_resume_when(
11311136
zend_coroutine_t *coroutine,
11321137
zend_async_event_t *event,

0 commit comments

Comments
 (0)