Io module

io_run

procedure · 2 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.

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);
}

Doesn't run in the browser (skipped on wasm).

io_run :: (proc: $P)

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.

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.

Parameters

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

done: bool;

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

    assert(done);
}

Doesn't run in the browser (skipped on wasm).

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

See also