@@ -342,6 +342,10 @@ static zend_class_entry* async_get_class_ce(zend_async_class type)
342342////////////////////////////////////////////////////////////////////
343343
344344#define AWAIT_ALL (await_context ) ((await_context)->waiting_count == 0 || (await_context)->waiting_count == (await_context)->total)
345+ #define ITERATOR_IS_FINISHED (await_context ) \
346+ ((await_context->ignore_errors ? await_context->success_count : await_context->resolved_count) >= await_context->waiting_count || \
347+ (await_context->total != 0 && await_context->resolved_count >= await_context->total) \
348+ )
345349
346350static zend_always_inline zend_async_event_t * zval_to_event (const zval * current )
347351{
@@ -442,6 +446,7 @@ void async_waiting_callback(
442446 if (exception == NULL && await_context -> results != NULL && ZEND_ASYNC_EVENT_WILL_ZVAL_RESULT (event ) && result != NULL ) {
443447
444448 const zval * success = NULL ;
449+ await_context -> success_count ++ ;
445450
446451 if (Z_TYPE (await_callback -> key ) == IS_STRING ) {
447452 success = zend_hash_update (await_context -> results , Z_STR (await_callback -> key ), result );
@@ -459,7 +464,7 @@ void async_waiting_callback(
459464 }
460465 }
461466
462- if (await_context -> resolved_count >= await_context -> waiting_count ) {
467+ if (UNEXPECTED ( ITERATOR_IS_FINISHED ( await_context )) ) {
463468 ZEND_ASYNC_RESUME (await_callback -> callback .coroutine );
464469 }
465470}
@@ -579,7 +584,7 @@ void iterator_coroutine_finish_callback(
579584 exception ,
580585 false
581586 );
582- } else if (iterator -> await_context -> resolved_count >= iterator -> await_context -> waiting_count ) {
587+ } else if (ITERATOR_IS_FINISHED ( iterator -> await_context ) ) {
583588 // If iteration is finished, resume the waiting coroutine
584589 ZEND_ASYNC_RESUME (iterator -> waiting_coroutine );
585590 }
@@ -669,6 +674,7 @@ void async_await_futures(
669674 await_context -> total = futures != NULL ? (int ) zend_hash_num_elements (futures ) : 0 ;
670675 await_context -> waiting_count = count > 0 ? count : await_context -> total ;
671676 await_context -> resolved_count = 0 ;
677+ await_context -> success_count = 0 ;
672678 await_context -> ignore_errors = ignore_errors ;
673679 await_context -> concurrency = concurrency ;
674680 await_context -> fill_missing_with_null = fill_missing_with_null ;
0 commit comments