@@ -45,16 +45,16 @@ static void coroutine_call_finally_handlers(async_coroutine_t *coroutine);
4545static void finally_context_dtor (finally_handlers_context_t * context );
4646
4747// Forward declarations for event system
48- static void coroutine_event_start (zend_async_event_t * event );
49- static void coroutine_event_stop (zend_async_event_t * event );
50- static void coroutine_add_callback (zend_async_event_t * event , zend_async_event_callback_t * callback );
51- static void coroutine_del_callback (zend_async_event_t * event , zend_async_event_callback_t * callback );
48+ static bool coroutine_event_start (zend_async_event_t * event );
49+ static bool coroutine_event_stop (zend_async_event_t * event );
50+ static bool coroutine_add_callback (zend_async_event_t * event , zend_async_event_callback_t * callback );
51+ static bool coroutine_del_callback (zend_async_event_t * event , zend_async_event_callback_t * callback );
5252static bool coroutine_replay (zend_async_event_t * event ,
5353 zend_async_event_callback_t * callback ,
5454 zval * result ,
5555 zend_object * * exception );
5656static zend_string * coroutine_info (zend_async_event_t * event );
57- static void coroutine_dispose (zend_async_event_t * event );
57+ static bool coroutine_dispose (zend_async_event_t * event );
5858
5959///////////////////////////////////////////////////////////
6060/// 2. Object Lifecycle Management
@@ -645,29 +645,28 @@ void async_coroutine_finalize(async_coroutine_t *coroutine)
645645 *
646646 * @param from_main For main coroutine
647647 */
648- void async_coroutine_suspend (const bool from_main )
648+ bool async_coroutine_suspend (const bool from_main )
649649{
650650 if (UNEXPECTED (from_main )) {
651651 // If the Scheduler was never used, it means no coroutines were created,
652652 // so execution can be finished without doing anything.
653653 if (circular_buffer_is_empty (& ASYNC_G (microtasks )) && zend_hash_num_elements (& ASYNC_G (coroutines )) == 0 ) {
654- return ;
654+ return true ;
655655 }
656656
657- async_scheduler_main_coroutine_suspend ();
658- return ;
657+ return async_scheduler_main_coroutine_suspend ();
659658 }
660659
661- async_scheduler_coroutine_suspend ();
660+ return async_scheduler_coroutine_suspend ();
662661}
663662
664- void async_coroutine_resume (zend_coroutine_t * coroutine , zend_object * error , const bool transfer_error )
663+ bool async_coroutine_resume (zend_coroutine_t * coroutine , zend_object * error , const bool transfer_error )
665664{
666665 zend_async_waker_t * waker = coroutine -> waker ;
667666
668667 if (UNEXPECTED (waker == NULL || waker -> status == ZEND_ASYNC_WAKER_NO_STATUS )) {
669668 async_throw_error ("Cannot resume a coroutine that has not been suspended" );
670- return ;
669+ return false ;
671670 }
672671
673672 if (error != NULL ) {
@@ -695,7 +694,7 @@ void async_coroutine_resume(zend_coroutine_t *coroutine, zend_object *error, con
695694 }
696695
697696 if (UNEXPECTED (waker -> status == ZEND_ASYNC_WAKER_QUEUED )) {
698- return ;
697+ return true ;
699698 }
700699
701700 const bool in_scheduler_context = ZEND_ASYNC_SCHEDULER_CONTEXT ;
@@ -707,12 +706,12 @@ void async_coroutine_resume(zend_coroutine_t *coroutine, zend_object *error, con
707706 // we will execute it immediately!
708707 if (UNEXPECTED (in_scheduler_context && coroutine == ZEND_ASYNC_CURRENT_COROUTINE )) {
709708 waker -> status = ZEND_ASYNC_WAKER_RESULT ;
710- return ;
709+ return true ;
711710 }
712711
713712 if (UNEXPECTED (circular_buffer_push_ptr_with_resize (& ASYNC_G (coroutine_queue ), coroutine )) == FAILURE ) {
714713 async_throw_error ("Failed to enqueue coroutine" );
715- return ;
714+ return false ;
716715 }
717716
718717 waker -> status = ZEND_ASYNC_WAKER_QUEUED ;
@@ -721,9 +720,11 @@ void async_coroutine_resume(zend_coroutine_t *coroutine, zend_object *error, con
721720 if (in_scheduler_context ) {
722721 circular_buffer_push_ptr_with_resize (& ASYNC_G (resumed_coroutines ), coroutine );
723722 }
723+
724+ return true;
724725}
725726
726- void async_coroutine_cancel (zend_coroutine_t * zend_coroutine ,
727+ bool async_coroutine_cancel (zend_coroutine_t * zend_coroutine ,
727728 zend_object * error ,
728729 bool transfer_error ,
729730 const bool is_safely )
@@ -734,7 +735,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
734735 OBJ_RELEASE (error );
735736 }
736737
737- return ;
738+ return true ;
738739 }
739740
740741 // An attempt to cancel a coroutine that is currently running.
@@ -757,7 +758,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
757758 zend_coroutine -> exception = async_new_exception (async_ce_cancellation_exception , "Coroutine cancelled" );
758759 }
759760
760- return ;
761+ return true ;
761762 }
762763
763764 zend_async_waker_t * waker = zend_async_waker_define (zend_coroutine );
@@ -768,7 +769,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
768769 error = async_new_exception (async_ce_cancellation_exception , "Coroutine cancelled" );
769770 transfer_error = true;
770771 if (UNEXPECTED (EG (exception ))) {
771- return ;
772+ return false ;
772773 }
773774 }
774775
@@ -786,7 +787,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
786787 OBJ_RELEASE (error );
787788 }
788789
789- return ;
790+ return true ;
790791 }
791792
792793 bool was_cancelled = ZEND_COROUTINE_IS_CANCELLED (zend_coroutine );
@@ -815,8 +816,7 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
815816 // In any other case, the cancellation exception overrides the existing exception.
816817 //
817818 ZEND_ASYNC_WAKER_APPLY_CANCELLATION (waker , error , transfer_error );
818- async_scheduler_coroutine_enqueue (zend_coroutine );
819- return ;
819+ return async_scheduler_coroutine_enqueue (zend_coroutine );
820820 }
821821
822822 // In safely mode, we don't forcibly terminate the coroutine,
@@ -827,7 +827,8 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
827827 if (transfer_error && error != NULL) {
828828 OBJ_RELEASE (error );
829829 }
830- return ;
830+
831+ return true;
831832 }
832833
833834 if (was_cancelled && waker -> error != NULL &&
@@ -839,29 +840,32 @@ void async_coroutine_cancel(zend_coroutine_t *zend_coroutine,
839840 ZEND_ASYNC_WAKER_APPLY_CANCELLATION (waker , error , transfer_error );
840841 }
841842
842- async_scheduler_coroutine_enqueue (zend_coroutine );
843+ return async_scheduler_coroutine_enqueue (zend_coroutine );
843844}
844845
845846///////////////////////////////////////////////////////////
846847/// 4. Event System Interface
847848///////////////////////////////////////////////////////////
848849
849- static void coroutine_event_start (zend_async_event_t * event )
850+ static bool coroutine_event_start (zend_async_event_t * event )
850851{
852+ return true;
851853}
852854
853- static void coroutine_event_stop (zend_async_event_t * event )
855+ static bool coroutine_event_stop (zend_async_event_t * event )
854856{
857+ // Empty implementation - coroutines don't need explicit stop
858+ return true;
855859}
856860
857- static void coroutine_add_callback (zend_async_event_t * event , zend_async_event_callback_t * callback )
861+ static bool coroutine_add_callback (zend_async_event_t * event , zend_async_event_callback_t * callback )
858862{
859- zend_async_callbacks_push (event , callback );
863+ return zend_async_callbacks_push (event , callback );
860864}
861865
862- static void coroutine_del_callback (zend_async_event_t * event , zend_async_event_callback_t * callback )
866+ static bool coroutine_del_callback (zend_async_event_t * event , zend_async_event_callback_t * callback )
863867{
864- zend_async_callbacks_remove (event , callback );
868+ return zend_async_callbacks_remove (event , callback );
865869}
866870
867871/**
@@ -930,10 +934,11 @@ static zend_string *coroutine_info(zend_async_event_t *event)
930934 }
931935}
932936
933- static void coroutine_dispose (zend_async_event_t * event )
937+ static bool coroutine_dispose (zend_async_event_t * event )
934938{
935939 async_coroutine_t * coroutine = (async_coroutine_t * ) event ;
936940 OBJ_RELEASE (& coroutine -> std );
941+ return true;
937942}
938943
939944///////////////////////////////////////////////////////////
0 commit comments