@@ -118,6 +118,7 @@ typedef struct _zend_async_context_s zend_async_context_t;
118
118
typedef struct _zend_async_waker_s zend_async_waker_t ;
119
119
typedef struct _zend_async_microtask_s zend_async_microtask_t ;
120
120
typedef struct _zend_async_scope_s zend_async_scope_t ;
121
+ typedef struct _zend_async_iterator_s zend_async_iterator_t ;
121
122
typedef struct _zend_fcall_s zend_fcall_t ;
122
123
typedef void (* zend_coroutine_entry_t )(void );
123
124
@@ -291,6 +292,28 @@ struct _zend_async_microtask_s {
291
292
uint32_t ref_count ;
292
293
};
293
294
295
+ ///////////////////////////////////////////////////////////////////
296
+ /// Async iterator structures
297
+ ///////////////////////////////////////////////////////////////////
298
+
299
+ struct _zend_async_iterator_s {
300
+ zend_async_microtask_t microtask ;
301
+ void (* run )(zend_async_iterator_t * iterator );
302
+ void (* run_in_coroutine )(zend_async_iterator_t * iterator , int32_t priority );
303
+ };
304
+
305
+ typedef zend_result (* zend_async_iterator_handler_t )(zend_async_iterator_t * iterator , zval * current , zval * key );
306
+
307
+ typedef zend_async_iterator_t * (* zend_async_new_iterator_t )(
308
+ zval * array ,
309
+ zend_object_iterator * zend_iterator ,
310
+ zend_fcall_t * fcall ,
311
+ zend_async_iterator_handler_t handler ,
312
+ unsigned int concurrency ,
313
+ int32_t priority ,
314
+ size_t iterator_size
315
+ );
316
+
294
317
///////////////////////////////////////////////////////////////////
295
318
/// Event Structures
296
319
///////////////////////////////////////////////////////////////////
@@ -1065,6 +1088,9 @@ ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn;
1065
1088
ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn ;
1066
1089
ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn ;
1067
1090
1091
+ /* Iterator API */
1092
+ ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn ;
1093
+
1068
1094
/* Context API */
1069
1095
ZEND_API extern zend_async_new_context_t zend_async_new_context_fn ;
1070
1096
@@ -1132,7 +1158,8 @@ ZEND_API bool zend_async_scheduler_register(
1132
1158
zend_async_get_coroutines_t get_coroutines_fn ,
1133
1159
zend_async_add_microtask_t add_microtask_fn ,
1134
1160
zend_async_get_awaiting_info_t get_awaiting_info_fn ,
1135
- zend_async_get_class_ce_t get_class_ce_fn
1161
+ zend_async_get_class_ce_t get_class_ce_fn ,
1162
+ zend_async_new_iterator_t new_iterator_fn
1136
1163
);
1137
1164
1138
1165
ZEND_API bool zend_async_reactor_register (
@@ -1314,6 +1341,12 @@ END_EXTERN_C()
1314
1341
#define ZEND_ASYNC_SOCKET_LISTEN_EX (host , port , backlog , extra_size ) \
1315
1342
zend_async_socket_listen_fn(host, port, backlog, extra_size)
1316
1343
1344
+ /* Iterator API Macros */
1345
+ #define ZEND_ASYNC_NEW_ITERATOR (array , zend_iterator , fcall , handler , concurrency , priority ) \
1346
+ zend_async_new_iterator_fn(array, zend_iterator, fcall, handler, concurrency, priority, 0)
1347
+ #define ZEND_ASYNC_NEW_ITERATOR_EX (array , zend_iterator , fcall , handler , concurrency , priority , size ) \
1348
+ zend_async_new_iterator_fn(array, zend_iterator, fcall, handler, concurrency, priority, size)
1349
+
1317
1350
/* Context API Macros */
1318
1351
#define ZEND_ASYNC_NEW_CONTEXT (parent ) zend_async_new_context_fn(parent)
1319
1352
#define ZEND_ASYNC_CURRENT_CONTEXT (ZEND_ASYNC_G(coroutine) != NULL ? ZEND_ASYNC_G(coroutine)->scope->context : NULL)
0 commit comments