Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

swapCancelProtection

Updates the current task's cancel protection state (see CancelProtection).

The typical usage for this function is to protect a block of code from cancelation:

const old_cancel_protect = io.swapCancelProtection(.blocked);
defer _ = io.swapCancelProtection(old_cancel_protect);
doSomeWork() catch |err| switch (err) {
    error.Canceled => unreachable,
};

For a description of cancelation and cancelation points, see Future.cancel.

Io.swapCancelProtection
pub fn swapCancelProtection(io: Io, new: CancelProtection) CancelProtection

File

lib/std/Io.zig:1368

Code

pub fn swapCancelProtection(io: Io, new: CancelProtection) CancelProtection {
    return io.vtable.swapCancelProtection(io.userdata, new);
}