4 ms·
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.a
by messe 1y 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