Not an answer, but I wish std.Io would adopt something like this:
var timeout: zio.Timeout = .init;
defer timeout.clear(rt);
timeout.set(rt, timeout_ms * std.time.ns_per_ms);
// anything further will be auto-canceled if the timeout triggers
// you can catch the error and remap it, if needed
I found this to be the only sensible way of dealing with timeout in async context.
that seems convenient but limiting, what if i dont want them all to have the same timeout, what if i want no timeout for some. what if i want to add a timeout to an existing task.
It depends on you use it. You can use this for in front of individual operations, or you can use it in front of a loop to have a more global effect.
In the original example, continueTransactionshas no timeout configured, so it can theoretically block forever. You pretty much never want that.
I found that the most common timeout handling in my code was something like this:
deadline = now + timeout
while (true) {
remaining = deadline - now
if (remaining < 0) {
return error.Timeout
}
do_something(timeout=remaining)
}
My zio.Timeout is akin to the Go context with deadline, but instead of select waiting on the done channel, this is done via cancellation. The most similar concept is Python asyncio.timeout.
Timeout is more flexible, it can be a duration, deadline or none.
I imagine there will be helper functions in the future, for now you can make your own to make it less verbose.
Not sure there is anything to do about that, it supports operations between different clocks, so you have to specify.
if its common enough to use the same clock, then there might be a wrapper for that in the future.
as always you can make one yourself.
I don’t understand why a user would have an infinite (none) timeout. In this instance, each call to sendTransactions corresponds to a single ethernet frame and each call to continueTransactions is a single call to a non-blocking recv syscall. The frame may be corrupted and destroyed by the underlying ethernet interface and could never return.
Maybe I am missing some other interface I should be using like Poller or something.