#zio-aio how does the magic happen

1 messages · Page 1 of 1 (latest)

glacial robin
#
    var startup: coro.ResetEvent = .{};
    _ = try scheduler.spawn(server, .{&startup}, .{});

I'm struggling to understand the inner workings on the zig-aio/ coro library. Lets take this piece of code:

    const RT = @TypeOf(@call(.auto, func, args));
    var task = try self.spawnAny(RT, func, args, opts);
    return task.generic(RT);
}

It seems the func is called (const RT = @TypeOf(@call(.auto, func, args));) , but later on its scheduled? Is this meant to only get the return type (@TypeOf evals the expression without side effects). Any clues?

polar mica
#

yes, @TypeOf has no side-effects

opal ruin
#

you are correct: https://ziglang.org/documentation/master/#TypeOf

@TypeOf is a special builtin function that takes any (non-zero) number of expressions as parameters and returns the type of the result, using Peer Type Resolution.

The expressions are evaluated, however they are guaranteed to have no runtime side-effects:

glacial robin
#

does this mean that the code is not executed but only resolved?

opal ruin
#

yeah. it analyzes it but nothing gets executed at runtime