LEVIATHAN vd52e79c4 · d52e79c486

Standard Library · ffi

attribute mayCallback

Asserts that a foreign function may call back into Leviathan through a callback registered earlier.

since 0.1.0-alpha.1linuxwindowswasm

Overview

A foreign function with a function-typed parameter is already treated this way. Add the mark to a function that runs a callback it was handed by an earlier call, such as one that drives an event loop; without it, a callback that waits with await while that function is running fails. The compiler cannot check the claim.

Examples

A function that runs a stored callback

uses ffi;
use ffi;
use io::console;

@extern("c")
@mayCallback
void qsort(Block base, int nmemb, int size, (Ptr, Ptr) => int32 compar);

void main() {
    Block data = Block(8);
    data.setInt32(0, 9);
    data.setInt32(4, 3);
    Callback cmp = ffi::callback::<(Ptr, Ptr) => int32>((Ptr a, Ptr b) => {
        return ffi::view(a, 4).int32At(0) < ffi::view(b, 4).int32At(0) ? -1 : 1;
    });
    qsort(data, 2, 4, cmp);
    console.writeln(data.int32At(0));
    cmp.close();
}
main();
3

Fields

value

bool value

Whether the mark applies.