@@ -119,6 +119,11 @@ typedef enum
119119 * zend_coroutine_t is a Basic data structure that represents a coroutine in the Zend Engine.
120120 */
121121typedef struct _zend_coroutine_s zend_coroutine_t ;
122+
123+ /**
124+ * zend_future_t is a data structure that represents a future result container.
125+ */
126+ typedef struct _zend_future_s zend_future_t ;
122127typedef struct _zend_async_context_s zend_async_context_t ;
123128typedef struct _zend_async_waker_s zend_async_waker_t ;
124129typedef struct _zend_async_microtask_s zend_async_microtask_t ;
@@ -127,6 +132,9 @@ typedef struct _zend_async_iterator_s zend_async_iterator_t;
127132typedef struct _zend_fcall_s zend_fcall_t ;
128133typedef void (* zend_coroutine_entry_t )(void );
129134
135+ /* Future resolve function type */
136+ typedef void (* zend_future_resolve_t )(zend_future_t * future , zval * value , zend_object * exception , bool transfer_error );
137+
130138/* Coroutine Switch Handlers */
131139typedef struct _zend_coroutine_switch_handler_s zend_coroutine_switch_handler_t ;
132140typedef struct _zend_coroutine_switch_handlers_vector_s zend_coroutine_switch_handlers_vector_t ;
@@ -203,6 +211,7 @@ typedef zend_array* (*zend_async_get_coroutines_t)(void);
203211typedef void (* zend_async_add_microtask_t )(zend_async_microtask_t * microtask );
204212typedef zend_array * (* zend_async_get_awaiting_info_t )(zend_coroutine_t * coroutine );
205213typedef zend_class_entry * (* zend_async_get_class_ce_t )(zend_async_class type );
214+ typedef zend_future_t * (* zend_async_future_create_t )(bool thread_safe , size_t extra_size );
206215
207216typedef void (* zend_async_reactor_startup_t )(void );
208217typedef void (* zend_async_reactor_shutdown_t )(void );
@@ -963,6 +972,25 @@ struct _zend_coroutine_s {
963972 zend_coroutine_switch_handlers_vector_t * switch_handlers ;
964973};
965974
975+ /**
976+ * zend_future_t structure represents a future result container.
977+ * It inherits from zend_async_event_t to participate in the event system.
978+ */
979+ struct _zend_future_s {
980+ zend_async_event_t event ; /* Event inheritance (first member) */
981+ zval result ; /* Result value (UNDEF = pending) */
982+ zend_object * exception ; /* Exception object (NULL = no error) */
983+
984+ /* Debug information */
985+ zend_string * filename ; /* Creation file */
986+ uint32_t lineno ; /* Creation line */
987+ zend_string * resolved_filename ; /* Resolution file */
988+ uint32_t resolved_lineno ; /* Resolution line */
989+
990+ /* Resolution method */
991+ zend_future_resolve_t resolve ;
992+ };
993+
966994/**
967995 * The macro evaluates to TRUE if the coroutine is in a waiting state —
968996 * either waiting for events or waiting in the execution queue.
@@ -1177,6 +1205,7 @@ ZEND_API extern zend_async_get_coroutines_t zend_async_get_coroutines_fn;
11771205ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn ;
11781206ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn ;
11791207ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn ;
1208+ ZEND_API extern zend_async_future_create_t zend_async_future_create_fn ;
11801209
11811210/* Iterator API */
11821211ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn ;
@@ -1361,6 +1390,10 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
13611390
13621391ZEND_API void zend_async_call_main_coroutine_start_handlers (zend_coroutine_t * main_coroutine );
13631392
1393+ /* Future API Functions */
1394+ #define ZEND_ASYNC_NEW_FUTURE (thread_safe ) zend_async_future_create_fn(thread_safe, 0)
1395+ #define ZEND_ASYNC_NEW_FUTURE_EX (thread_safe , extra_size ) zend_async_future_create_fn(thread_safe, extra_size)
1396+
13641397END_EXTERN_C ()
13651398
13661399#define ZEND_ASYNC_IS_ENABLED () zend_async_is_enabled()
0 commit comments