pub fn Future(Result: type) type any_future: ?*AnyFutureresult: Resultpub fn cancel(f: *@This(), io: Io) ResultEquivalent to await but places a cancelation request. This causes the task to receive error.Canceled from its next "cancelation point" (if any). A cancelation point is a call to a function in Io which can return error.Canceled.
After cancelation of a task is requested, only the next cancelation point in that task will return error.Canceled: future points will not re-signal the cancelation. As such, it is usually a bug to ignore error.Canceled. However, to defer handling cancelation requests, see also recancel and CancelProtection.
Idempotent. Not threadsafe.
pub fn await(f: *@This(), io: Io) ResultIdempotent. Not threadsafe.
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320pub fn Future(Result: type) type {
return struct {
any_future: ?*AnyFuture,
result: Result,
/// Equivalent to `await` but places a cancelation request. This causes the task to receive
/// `error.Canceled` from its next "cancelation point" (if any). A cancelation point is a
/// call to a function in `Io` which can return `error.Canceled`.
///
/// After cancelation of a task is requested, only the next cancelation point in that task
/// will return `error.Canceled`: future points will not re-signal the cancelation. As such,
/// it is usually a bug to ignore `error.Canceled`. However, to defer handling cancelation
/// requests, see also `recancel` and `CancelProtection`.
///
/// Idempotent. Not threadsafe.
pub fn cancel(f: *@This(), io: Io) Result {
const any_future = f.any_future orelse return f.result;
io.vtable.cancel(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
f.any_future = null;
return f.result;
}
/// Idempotent. Not threadsafe.
pub fn await(f: *@This(), io: Io) Result {
const any_future = f.any_future orelse return f.result;
io.vtable.await(io.userdata, any_future, @ptrCast(&f.result), .of(Result));
f.any_future = null;
return f.result;
}
};
}