1919#include "zend_fibers.h"
2020#include "zend_globals.h"
2121
22- #define ZEND_ASYNC_API "TrueAsync API v0.3 .0"
22+ #define ZEND_ASYNC_API "TrueAsync API v0.4 .0"
2323#define ZEND_ASYNC_API_VERSION_MAJOR 0
24- #define ZEND_ASYNC_API_VERSION_MINOR 3
24+ #define ZEND_ASYNC_API_VERSION_MINOR 4
2525#define ZEND_ASYNC_API_VERSION_PATCH 0
2626
2727#define ZEND_ASYNC_API_VERSION_NUMBER \
@@ -119,6 +119,16 @@ 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 ;
127+
128+ /**
129+ * zend_async_channel_t is a data structure that represents a communication channel.
130+ */
131+ typedef struct _zend_async_channel_s zend_async_channel_t ;
122132typedef struct _zend_async_context_s zend_async_context_t ;
123133typedef struct _zend_async_waker_s zend_async_waker_t ;
124134typedef struct _zend_async_microtask_s zend_async_microtask_t ;
@@ -127,6 +137,13 @@ typedef struct _zend_async_iterator_s zend_async_iterator_t;
127137typedef struct _zend_fcall_s zend_fcall_t ;
128138typedef void (* zend_coroutine_entry_t )(void );
129139
140+ /* Future resolve function type */
141+ typedef void (* zend_future_resolve_t )(zend_future_t * future , zval * value , zend_object * exception , bool transfer_error );
142+
143+ /* Channel method function types */
144+ typedef bool (* zend_channel_send_t )(zend_async_channel_t * channel , zval * value );
145+ typedef bool (* zend_channel_receive_t )(zend_async_channel_t * channel , zval * result );
146+
130147/* Coroutine Switch Handlers */
131148typedef struct _zend_coroutine_switch_handler_s zend_coroutine_switch_handler_t ;
132149typedef struct _zend_coroutine_switch_handlers_vector_s zend_coroutine_switch_handlers_vector_t ;
@@ -203,6 +220,8 @@ typedef zend_array* (*zend_async_get_coroutines_t)(void);
203220typedef void (* zend_async_add_microtask_t )(zend_async_microtask_t * microtask );
204221typedef zend_array * (* zend_async_get_awaiting_info_t )(zend_coroutine_t * coroutine );
205222typedef zend_class_entry * (* zend_async_get_class_ce_t )(zend_async_class type );
223+ typedef zend_future_t * (* zend_async_future_create_t )(bool thread_safe , size_t extra_size );
224+ typedef zend_async_channel_t * (* zend_async_channel_create_t )(size_t buffer_size , bool resizable , bool thread_safe , size_t extra_size );
206225
207226typedef void (* zend_async_reactor_startup_t )(void );
208227typedef void (* zend_async_reactor_shutdown_t )(void );
@@ -963,6 +982,41 @@ struct _zend_coroutine_s {
963982 zend_coroutine_switch_handlers_vector_t * switch_handlers ;
964983};
965984
985+ /**
986+ * zend_future_t structure represents a future result container.
987+ * It inherits from zend_async_event_t to participate in the event system.
988+ */
989+ struct _zend_future_s {
990+ zend_async_event_t event ; /* Event inheritance (first member) */
991+ zval result ; /* Result value (UNDEF = pending) */
992+ zend_object * exception ; /* Exception object (NULL = no error) */
993+
994+ /* Debug information */
995+ zend_string * filename ; /* Creation file */
996+ uint32_t lineno ; /* Creation line */
997+ zend_string * resolved_filename ; /* Resolution file */
998+ uint32_t resolved_lineno ; /* Resolution line */
999+
1000+ /* Resolution method */
1001+ zend_future_resolve_t resolve ;
1002+ };
1003+
1004+ /**
1005+ * zend_async_channel_t structure represents a communication channel.
1006+ * It inherits from zend_async_event_t to participate in the event system.
1007+ */
1008+ struct _zend_async_channel_s {
1009+ zend_async_event_t event ; /* Event inheritance (first member) */
1010+
1011+ /* Debug information */
1012+ zend_string * filename ; /* Creation file */
1013+ uint32_t lineno ; /* Creation line */
1014+
1015+ /* Channel-specific method pointers */
1016+ zend_channel_send_t send ; /* Send method */
1017+ zend_channel_receive_t receive ; /* Receive method */
1018+ };
1019+
9661020/**
9671021 * The macro evaluates to TRUE if the coroutine is in a waiting state —
9681022 * either waiting for events or waiting in the execution queue.
@@ -1177,6 +1231,8 @@ ZEND_API extern zend_async_get_coroutines_t zend_async_get_coroutines_fn;
11771231ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn ;
11781232ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn ;
11791233ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn ;
1234+ ZEND_API extern zend_async_future_create_t zend_async_future_create_fn ;
1235+ ZEND_API extern zend_async_channel_create_t zend_async_channel_create_fn ;
11801236
11811237/* Iterator API */
11821238ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn ;
@@ -1361,6 +1417,14 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
13611417
13621418ZEND_API void zend_async_call_main_coroutine_start_handlers (zend_coroutine_t * main_coroutine );
13631419
1420+ /* Future API Functions */
1421+ #define ZEND_ASYNC_NEW_FUTURE (thread_safe ) zend_async_future_create_fn(thread_safe, 0)
1422+ #define ZEND_ASYNC_NEW_FUTURE_EX (thread_safe , extra_size ) zend_async_future_create_fn(thread_safe, extra_size)
1423+
1424+ /* Channel API Functions */
1425+ #define ZEND_ASYNC_NEW_CHANNEL (buffer_size , resizable , thread_safe ) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, 0)
1426+ #define ZEND_ASYNC_NEW_CHANNEL_EX (buffer_size , resizable , thread_safe , extra_size ) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, extra_size)
1427+
13641428END_EXTERN_C ()
13651429
13661430#define ZEND_ASYNC_IS_ENABLED () zend_async_is_enabled()
0 commit comments