Skip to content

#48: rename CancellationException => CancellationError #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion async.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function getCoroutines(): array {}
/**
* Start the graceful shutdown of the Scheduler.
*/
function gracefulShutdown(?CancellationException $cancellationException = null): void {}
function gracefulShutdown(?CancellationError $cancellationError = null): void {}

/**
* Execute an external program.
Expand Down
188 changes: 54 additions & 134 deletions async_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: d217fc8dbb5aa518add60c4d99d3e7a356fbd41f */
* Stub hash: aca45cee02a4df47e8e1bc3c2517e6925bd522a9 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_Async_spawn, 0, 1, Async\\Coroutine, 0)
ZEND_ARG_TYPE_INFO(0, task, IS_CALLABLE, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, task, IS_CALLABLE, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_Async_spawnWith, 0, 2, Async\\Coroutine, 0)
ZEND_ARG_OBJ_INFO(0, provider, Async\\ScopeProvider, 0)
ZEND_ARG_TYPE_INFO(0, task, IS_CALLABLE, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_ARG_OBJ_INFO(0, provider, Async\\ScopeProvider, 0)
ZEND_ARG_TYPE_INFO(0, task, IS_CALLABLE, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_suspend, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_protect, 0, 1, IS_MIXED, 0)
ZEND_ARG_OBJ_INFO(0, closure, Closure, 0)
ZEND_ARG_OBJ_INFO(0, closure, Closure, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_await, 0, 1, IS_MIXED, 0)
ZEND_ARG_OBJ_INFO(0, awaitable, Async\\Awaitable, 0)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_OBJ_INFO(0, awaitable, Async\\Awaitable, 0)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOrFail, 0, 1, IS_MIXED, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_END_ARG_INFO()

#define arginfo_Async_awaitFirstSuccess arginfo_Async_awaitAnyOrFail

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAllOrFail, 0, 1, IS_ARRAY, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAll, 0, 1, IS_ARRAY, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fillNull, _IS_BOOL, 0, "false")
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fillNull, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOfOrFail, 0, 2, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOf, 0, 2, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fillNull, _IS_BOOL, 0, "false")
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fillNull, _IS_BOOL, 0, "false")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_delay, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, ms, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, ms, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_Async_timeout, 0, 1, Async\\Awaitable, 0)
ZEND_ARG_TYPE_INFO(0, ms, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, ms, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_Async_currentContext, 0, 0, Async\\Context, 0)
Expand All @@ -81,7 +81,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_getCoroutines, 0, 0, IS_AR
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_gracefulShutdown, 0, 0, IS_VOID, 0)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellationException, Async\\CancellationException, 1, "null")
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellationError, Async\\CancellationError, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Async_Timeout___construct, 0, 0, 0)
Expand Down Expand Up @@ -109,112 +109,32 @@ ZEND_FUNCTION(Async_gracefulShutdown);
ZEND_METHOD(Async_Timeout, __construct);

static const zend_function_entry ext_functions[] = {
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "spawn"),
zif_Async_spawn,
arginfo_Async_spawn,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "spawnWith"),
zif_Async_spawnWith,
arginfo_Async_spawnWith,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "suspend"),
zif_Async_suspend,
arginfo_Async_suspend,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "protect"),
zif_Async_protect,
arginfo_Async_protect,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "await"), zif_Async_await, arginfo_Async_await, 0, NULL, NULL)
ZEND_RAW_FENTRY(
ZEND_NS_NAME("Async", "awaitAnyOrFail"),
zif_Async_awaitAnyOrFail,
arginfo_Async_awaitAnyOrFail,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitFirstSuccess"),
zif_Async_awaitFirstSuccess,
arginfo_Async_awaitFirstSuccess,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAllOrFail"),
zif_Async_awaitAllOrFail,
arginfo_Async_awaitAllOrFail,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async",
"awaitAll"),
zif_Async_awaitAll,
arginfo_Async_awaitAll,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOfOrFail"),
zif_Async_awaitAnyOfOrFail,
arginfo_Async_awaitAnyOfOrFail,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOf"),
zif_Async_awaitAnyOf,
arginfo_Async_awaitAnyOf,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "delay"),
zif_Async_delay,
arginfo_Async_delay,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "timeout"),
zif_Async_timeout,
arginfo_Async_timeout,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "currentContext"),
zif_Async_currentContext,
arginfo_Async_currentContext,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(
ZEND_NS_NAME("Async", "coroutineContext"),
zif_Async_coroutineContext,
arginfo_Async_coroutineContext,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "currentCoroutine"),
zif_Async_currentCoroutine,
arginfo_Async_currentCoroutine,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "rootContext"),
zif_Async_rootContext,
arginfo_Async_rootContext,
0,
NULL,
NULL) ZEND_RAW_FENTRY(ZEND_NS_NAME("Async",
"getCoroutines"),
zif_Async_getCoroutines,
arginfo_Async_getCoroutines,
0,
NULL,
NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "gracefulShutdown"),
zif_Async_gracefulShutdown,
arginfo_Async_gracefulShutdown,
0,
NULL,
NULL) ZEND_FE_END
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "spawn"), zif_Async_spawn, arginfo_Async_spawn, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "spawnWith"), zif_Async_spawnWith, arginfo_Async_spawnWith, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "suspend"), zif_Async_suspend, arginfo_Async_suspend, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "protect"), zif_Async_protect, arginfo_Async_protect, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "await"), zif_Async_await, arginfo_Async_await, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOrFail"), zif_Async_awaitAnyOrFail, arginfo_Async_awaitAnyOrFail, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitFirstSuccess"), zif_Async_awaitFirstSuccess, arginfo_Async_awaitFirstSuccess, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAllOrFail"), zif_Async_awaitAllOrFail, arginfo_Async_awaitAllOrFail, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAll"), zif_Async_awaitAll, arginfo_Async_awaitAll, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOfOrFail"), zif_Async_awaitAnyOfOrFail, arginfo_Async_awaitAnyOfOrFail, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOf"), zif_Async_awaitAnyOf, arginfo_Async_awaitAnyOf, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "delay"), zif_Async_delay, arginfo_Async_delay, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "timeout"), zif_Async_timeout, arginfo_Async_timeout, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "currentContext"), zif_Async_currentContext, arginfo_Async_currentContext, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "coroutineContext"), zif_Async_coroutineContext, arginfo_Async_coroutineContext, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "currentCoroutine"), zif_Async_currentCoroutine, arginfo_Async_currentCoroutine, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "rootContext"), zif_Async_rootContext, arginfo_Async_rootContext, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "getCoroutines"), zif_Async_getCoroutines, arginfo_Async_getCoroutines, 0, NULL, NULL)
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "gracefulShutdown"), zif_Async_gracefulShutdown, arginfo_Async_gracefulShutdown, 0, NULL, NULL)
ZEND_FE_END
};

static const zend_function_entry class_Async_Timeout_methods[] = { ZEND_ME(
Async_Timeout, __construct, arginfo_class_Async_Timeout___construct, ZEND_ACC_PRIVATE) ZEND_FE_END };
static const zend_function_entry class_Async_Timeout_methods[] = {
ZEND_ME(Async_Timeout, __construct, arginfo_class_Async_Timeout___construct, ZEND_ACC_PRIVATE)
ZEND_FE_END
};

static zend_class_entry *register_class_Async_Awaitable(void)
{
Expand Down
12 changes: 7 additions & 5 deletions coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ METHOD(cancel)
{
zend_object *exception = NULL;

zend_class_entry *ce_cancellation_exception = ZEND_ASYNC_GET_CE(ZEND_ASYNC_EXCEPTION_CANCELLATION);

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL;
Z_PARAM_OBJ_OF_CLASS_OR_NULL(exception, zend_ce_cancellation_exception)
Z_PARAM_OBJ_OF_CLASS_OR_NULL(exception, ce_cancellation_exception)
ZEND_PARSE_PARAMETERS_END();

ZEND_ASYNC_CANCEL(&THIS_COROUTINE->coroutine, exception, false);
Expand Down Expand Up @@ -566,7 +568,7 @@ void async_coroutine_finalize(zend_fiber_transfer *transfer, async_coroutine_t *
// Hold the exception inside coroutine if it is not NULL.
if (exception != NULL) {
if (coroutine->coroutine.exception != NULL) {
if (false == instanceof_function(exception->ce, zend_ce_cancellation_exception)) {
if (false == instanceof_function(exception->ce, ZEND_ASYNC_GET_CE(ZEND_ASYNC_EXCEPTION_CANCELLATION))) {
zend_exception_set_previous(exception, coroutine->coroutine.exception);
coroutine->coroutine.exception = exception;
GC_ADDREF(exception);
Expand Down Expand Up @@ -611,7 +613,7 @@ void async_coroutine_finalize(zend_fiber_transfer *transfer, async_coroutine_t *
// Cancellation-type exceptions are considered handled in all cases and are not propagated further.
if (exception != NULL &&
(ZEND_COROUTINE_IS_EXCEPTION_HANDLED(&coroutine->coroutine) ||
instanceof_function(exception->ce, zend_ce_cancellation_exception))) {
instanceof_function(exception->ce, ZEND_ASYNC_GET_CE(ZEND_ASYNC_EXCEPTION_CANCELLATION)))) {
OBJ_RELEASE(exception);
exception = NULL;
}
Expand Down Expand Up @@ -968,7 +970,7 @@ void async_coroutine_resume(zend_coroutine_t *coroutine, zend_object *error, con
if (error != NULL) {
if (coroutine->waker->error != NULL) {

if (false == instanceof_function(error->ce, zend_ce_cancellation_exception)) {
if (false == instanceof_function(error->ce, ZEND_ASYNC_GET_CE(ZEND_ASYNC_EXCEPTION_CANCELLATION))) {
zend_exception_set_previous(error, coroutine->waker->error);
coroutine->waker->error = error;

Expand Down Expand Up @@ -1123,7 +1125,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
}

if (was_cancelled && waker->error != NULL &&
instanceof_function(waker->error->ce, zend_ce_cancellation_exception)) {
instanceof_function(waker->error->ce, ZEND_ASYNC_GET_CE(ZEND_ASYNC_EXCEPTION_CANCELLATION))) {
if (transfer_error) {
OBJ_RELEASE(error);
}
Expand Down
4 changes: 2 additions & 2 deletions coroutine.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getResult(): mixed {}
/**
* Returns the Coroutine exception when finished.
* If the Coroutine is not finished, it will return null.
* If the Coroutine is cancelled, it will return a CancellationException.
* If the Coroutine is cancelled, it will return a CancellationError.
*
* @throws \RuntimeException if the Coroutine is running
*/
Expand Down Expand Up @@ -105,7 +105,7 @@ public function getAwaitingInfo(): array {}
/**
* Cancel the coroutine.
*/
public function cancel(?\CancellationException $cancellationException = null): void {}
public function cancel(?CancellationError $CancellationError = null): void {}

/**
* Define a callback to be executed when the coroutine is finished.
Expand Down
Loading
Loading