Comment by Galanwe

Comment by Galanwe 20 hours ago

1 reply

So you have to do:

    io.async(saveFile, .{io, data, "saveA.txt"}).await(io);
That is 3 references to `io` in a single call.

Considering there is very little use case for mix and matching different Ios, any chance of having some kind of default / context IO to avoid all these ?

messe 20 hours ago

If you're going to immediately await it, you can just do

    saveFile(io, data, "saveA.txt");
EDIT: following up on that, I'm actually not sure that

    io.async(saveFile, .{io, data, "saveA.txt"}).await(io);
will even be valid code. Futures in this article are declared as var, meaning mutable. This appears to be because Future.await is going to take a pointer as its initial argument. However, because it's a temporary and therefore treated as const, the return value of io.async will not be passable to a .await function expecting a *Future as its initial argument without first being stored in a mutable var.

So this would be valid:

    var save_future = io.async(saveFile, .{io, data, "saveA.txt"});
    save_future.await(io);
But the original presented in the parent comment would be equivalent to the following, and therefore invalid:

    const save_future = io.async(saveFile, .{io, data, "saveA.txt"});
    save_future.await(io); // compile error