Search by

fiber-interop / trueasync

frodeborli

TrueAsync (ext true_async) coroutine adapter for fiber-interop/api: go, await, sleep, readable, writable on Async\Coroutine.

Package info

github.com/fiber-interop/trueasync

pkg:composer/fiber-interop/trueasync

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-10-19 18:23 UTC

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's Scope (TrueAsync has no spawn hook). Only tasks created through fiber\go inherit it.
  • fclose() of a stream does not wake a stream_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.