Skip to content

True async api stable #19142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 177 commits into
base: master
Choose a base branch
from
Open

Conversation

EdmondDantes
Copy link

TrueAsync engine API

The TrueAsync engine API defines a pluggable interface that lets extensions register different async backends while the core supplies standardized primitives.

Key Components

  • Events: Low‑level representation of sockets, timers and other readiness sources
  • Coroutines: Stackful tasks
  • Scopes: Hierarchical lifetime management enabling grouped cancellation
  • Wakers: Event‑completion handlers that resume suspended coroutines

PR for https://wiki.php.net/rfc/true_async_engine_api

EdmondDantes and others added 30 commits May 24, 2025 13:49
Initial version of the asynchronous API for PHP. Includes only the API itself and the necessary core changes required for the API to function.
…ized into a method for retrieving any ClassEntry.

  Now, using this API function, you can obtain the required class entry by a type descriptor type.
Added API functions for coroutine context management:
- zend_async_context_set_t: set value by string or object key
- zend_async_context_get_t: get value by string or object key
- zend_async_context_has_t: check if key exists
- zend_async_context_delete_t: delete key-value pair

Includes convenience macros for easier usage:
ZEND_ASYNC_CONTEXT_SET_STR/OBJ, GET_STR/OBJ, HAS_STR/OBJ, DELETE_STR/OBJ
Added complete Context API implementation:
- Updated zend_async_scheduler_register signature to accept context functions
- Added context function pointers and registration in zend_async_API.c
- Context API supports both string and object keys
- Includes convenience macros for easy usage

This completes the core API infrastructure for coroutine context management.
- Remove separate context_set, context_get, context_has, context_delete functions
- Add single zend_async_new_context_fn function to create context instances
- Move context implementation to ext/async module using zend_async_context_t structure
- Update scheduler registration to include new_context_fn parameter
- Add context field to zend_async_globals_t and zend_coroutine_s
- Simplify Context API macros to ZEND_ASYNC_NEW_CONTEXT and ZEND_ASYNC_CURRENT_CONTEXT
% removal of the current Scope from the global structure
… always needs to be explicitly known. Macros like ZEND_ASYNC_CURRENT_SCOPE were updated.

  A new macro ZEND_ASYNC_MAIN_SCOPE was added for the main Scope.
…main coroutine can correctly return control.
* add macro START_REACTOR_OR_RETURN for reactor autostart
… is now passed to the main coroutine’s finalize method instead of being displayed on screen.

* Fixed an issue with correctly passing the exception into the coroutine.
… captures the exception, marking it as handled in another coroutine.
Comment on lines +312 to +326
ZEND_API bool zend_async_reactor_register(char *module, bool allow_override,
zend_async_reactor_startup_t reactor_startup_fn,
zend_async_reactor_shutdown_t reactor_shutdown_fn,
zend_async_reactor_execute_t reactor_execute_fn,
zend_async_reactor_loop_alive_t reactor_loop_alive_fn,
zend_async_new_socket_event_t new_socket_event_fn,
zend_async_new_poll_event_t new_poll_event_fn,
zend_async_new_timer_event_t new_timer_event_fn,
zend_async_new_signal_event_t new_signal_event_fn,
zend_async_new_process_event_t new_process_event_fn,
zend_async_new_thread_event_t new_thread_event_fn,
zend_async_new_filesystem_event_t new_filesystem_event_fn,
zend_async_getnameinfo_t getnameinfo_fn, zend_async_getaddrinfo_t getaddrinfo_fn,
zend_async_freeaddrinfo_t freeaddrinfo_fn, zend_async_new_exec_event_t new_exec_event_fn,
zend_async_exec_t exec_fn, zend_async_new_trigger_event_t new_trigger_event_fn)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to put this into a struct so it can be extended without necessarily breaking the api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants