top | item 45718400

(no title)

noselasd | 4 months ago

Mostly out of curiosity, a read on a TCP connection could easily block for a month - how does the I/O timeout interface look like ? e.g. if you want to send an application level heartbeat when a read has blocked for 30 seconds.

discuss

order

secondcoming|4 months ago

This is very true. Most examples of async io I've seen - regardless of the framework - gloss over timeouts and cancellation. It's really the hardest part. Reading and writing asynchronously from a socket, or whatever, is the straightforward part.

lukaslalinsky|4 months ago

I don't have a good answer for that yet, mostly because TCP reads are expected to be done through std.Io.Reader which isn't aware of timeouts.

What I envision is something like `asyncio.timeout` in Python, where you start a timeout and let the code run as usual. If it's in I/O sleep when the timeout fires, it will get woken up and the operation gets canceled.

I see something like this:

    var timeout: zio.Timeout = .init;
    defer timeout.cancel(rt);

    timeout.set(rt, 10);
    const n = try reader.interface.readVec(&data);

sgt|4 months ago

Are you working using Zig master with the new Io interface passed around, by the way?