Io module

io_run

procedureextensionexperimental2 overloadsSource

Runs proc as the first fiber of a new scheduler on this thread and returns when it has returned. Fibers it started that are still alive then are canceled, and run until they end. Everything that waits (sleep, accept, read, channels) runs inside it, and only the calling fiber waits, never the thread. The scheduler's memory is released when the call returns; the caller keeps what proc allocated. Do not call it from inside another io_run on the same thread.

Example↗
Io :: #import "Extensions/Io";

done: bool;

main :: () {
    Io.io_run(() {
        Io.sleep(1);
        done = true;
    });

    assert(done);
}
io_run :: (proc: $P)

Parameters

proc: $P
io_run :: (proc: $P, data: $T)

The io_run for a procedure that takes one argument: data is copied and handed to proc.

Parameters

proc: $P
data: $T
Example↗
Io :: #import "Extensions/Io";

Io.io_run((n: int) { assert(n == 3); }, 3);

See also