A coroutine library for Haxe, providing asynchronous calls, generators, structured concurrency, and more — across all major Haxe targets.
import hxcoro.Coro.*;
import hxcoro.CoroRun;
class Main {
@:coroutine static function greet():Void {
trace("Hello…");
delay(500); // suspend for 500 ms
trace("…World!");
}
static function main() {
CoroRun.run(_ -> greet());
}
}- Asynchronous calls — write asynchronous code in a straightforward sequential style using
@:coroutinemethods. - Structured concurrency — manage lightweight groups of child tasks with well-defined lifetimes and cancellation semantics.
- Generators — produce lazy sequences with
HaxeGenerator,Es6Generator,CsGenerator, and the async variantAsyncGenerator. - Cancellation — first-class
CancellationExceptionsupport throughout, withsuspendCancellablefor registering cleanup callbacks. - Dispatchers & schedulers — pluggable execution model; ships with
TrampolineDispatcher,ThreadPoolDispatcher, and (on C++)LuvDispatcher. - Cross-target — works on JS, HL, C++, JVM, Python, PHP, Neko, and Eval.
- JS Promise integration —
CoroRun.promisewraps a coroutine as ajs.lib.Promise;CoroRun.awaitsuspends on an existing Promise.
Tests live in the tests/ directory. Each supported target has its own build file:
haxe --cwd tests build-eval.hxml # Eval (fastest, no extra tools needed)
haxe --cwd tests build-js.hxml # JavaScript (requires Node.js)
haxe --cwd tests build-hl.hxml # HashLink
haxe --cwd tests build-cpp.hxml # C++
haxe --cwd tests build-jvm.hxml # JVM
haxe --cwd tests build-python.hxml # Python
haxe --cwd tests build-php.hxml # PHP
haxe --cwd tests build-neko.hxml # Neko