Skip to content

Async core#22561

Draft
EdmondDantes wants to merge 2 commits into
php:masterfrom
true-async:async-core
Draft

Async core#22561
EdmondDantes wants to merge 2 commits into
php:masterfrom
true-async:async-core

Conversation

@EdmondDantes

Copy link
Copy Markdown

A lightweight asynchronous core without complex logic.

@EdmondDantes EdmondDantes marked this pull request as draft July 2, 2026 17:48
@EdmondDantes EdmondDantes force-pushed the async-core branch 4 times, most recently from 615d050 to ed9fe03 Compare July 2, 2026 18:11
@EdmondDantes EdmondDantes force-pushed the async-core branch 4 times, most recently from d7284f3 to 7aec489 Compare July 2, 2026 19:22
A mechanism-only async core, rethought from the TrueAsync ABI
(2973-line header) down to ~350 lines. The core contains NO policy:
no scheduler, no reactor, no event system. All behaviour arrives
through function-pointer slots registered by a provider.

The API consists of:

- zend_coroutine_t: thin coroutine structure. The lifecycle status
  (created/queued/running/suspended/finished) is packed into the low
  4 bits of the 32-bit flags word; modifier flags (cancelled, main)
  start at bit 4. No embedded waker - how a coroutine waits is the
  scheduler's implementation detail. Instead, whoever suspends a
  coroutine may attach an awaiting_info handler that describes the
  wait for diagnostics.

- Execution-flow context: fully opaque type accessed through slots -
  get_context(coroutine) with NULL meaning the current coroutine
  (ZEND_ASYNC_CURRENT_CONTEXT), context_find/set/unset. Storage,
  inheritance and lifetime live in the provider.

- Scheduler slots registered via a versioned struct
  (zend_async_scheduler_api_t): new_coroutine, enqueue_coroutine,
  suspend, resume, cancel, launch, shutdown, get_class_ce,
  call_on_main_stack + the four context slots. The size field keeps
  registration forward-compatible: new slots are appended at the end
  only.

- Per-thread globals: state, current/main coroutine, live coroutine
  count.

- Exception class registry: zend_async_class enum resolved through
  the get_class_ce slot; consumers throw with the regular engine API.

Unregistered slots fail with a clear error, so the API is inert until
a scheduler module registers itself.
Each fiber can be associated with a coroutine (fiber->coroutine,
NULL = legacy mode with unchanged behaviour). The caller field becomes
a union: in coroutine mode the fiber remembers the coroutine that
resumed it instead of a fiber context - the single point-to-point
link that replaces TrueAsync's resume/yield event pair.

Phase 2 (the actual cooperative switching through the scheduler
slots) requires a working scheduler to test against and comes with
the reference extension.
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.

1 participant