Cloudef / zig-aio

io_uring like asynchronous API and coroutine powered IO tasks for zig
https://cloudef.github.io/zig-aio/
MIT License
172 stars 8 forks source link

aio: multishot operations #7

Open Cloudef opened 3 months ago

Cloudef commented 3 months ago

It's possible to have multishot operations that take a callback parameter. These are important for repeating timers and socket accept loops. Should not need any special interface, but there might be some lifetime shenanigans that has to be taken in account.

Cloudef commented 3 months ago

How it could work:

fn acceptCallback(context: *anyopaque, socket: std.posix.socket_t, addr: std.posix.addrinfo) !void {
    // cancel from inside a callback
    return error.Canceled;
}

var id: aio.Id = undefined;
try io.single(aio.AcceptMultishot{ .callback = acceptCallback, .context = arg, .out_id = &id });
// cancel from outside the callback
io.single(aio.Cancel{ .id = id });