fiber-interop / trueasync
TrueAsync (ext true_async) coroutine adapter for fiber-interop/api: go, await, sleep, readable, writable on Async\Coroutine.
Requires
- php: ^8.6
- fiber-interop/api: ^0.3
- fiber-interop/scope: ^0.2 || ^0.3
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11
Suggests
- ext-true_async: TrueAsync 0.10+ (PHP 8.6 built with --enable-async)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-19 18:28:59 UTC
README
Adapter that runs the fiber-interop/api functions (fiber\go, await,
await_all, await_any, run, sleep, readable, writable) on TrueAsync coroutines, so a library written
against the api runs unchanged for TrueAsync users.
Install
composer require fiber-interop/api fiber-interop/trueasync
Requires PHP 8.6 built with TrueAsync and the true_async extension 0.10+ (tested on 0.10.0, ABI v0.26.0), for
example the trueasync/php-true-async Docker image. src/register.php registers the adapter only when the
extension is loaded.
Mapping
| api | TrueAsync |
|---|---|
go($f) |
Async\spawn(); returns a task wrapping the Async\Coroutine, running in the captured Scope |
await(task) |
Async\await(); repeatable, rethrows the same exception object; a timeout throws fiber\Timeout and leaves the task running |
await_all / await_any |
built on await over the tasks |
sleep() |
Async\delay() (whole milliseconds) |
readable() / writable() |
cooperative stream_select() |
run($f) |
runs $f in the main coroutine and waits for it |
Known differences
- Coroutines created with native
Async\spawn()do not join the creator'sScope(TrueAsync has no spawn hook). Only tasks created throughfiber\goinherit it. fclose()of a stream does not wake astream_select()waiting on it, so the adapter polls in 20 ms slices and notices the closed stream within one slice.- Sub-millisecond
stream_select()timeouts are rounded up to 1 ms because of a TrueAsync issue. - An unawaited coroutine that throws shuts the whole script down, so tasks never throw out of their coroutine: the exception is stored and delivered to whoever awaits the task.
Tests
vendor/bin/phpunit on a TrueAsync PHP: ConformanceTest runs all 22 api conformance examples, AdapterTest
covers go/await, repeated awaits, sleep overlap, timeouts and per-coroutine scope. In Docker, bin/tac php vendor/bin/phpunit
(bin/ta and bin/tac run the image with the current directory mounted; tac also disables xdebug for child processes).
dev/ holds exploratory scripts used while probing the runtime.