Judging by the fact that io.async doesn’t take an allocator, I’m assuming that this is not leaking memory, but might this leak anything else? File descriptors?
Actually, I’ve just wrapped this in a test, and the debug allocator did detect a leak. I wonder, how one would write such a loop then. Create a std.Io.Group and call await on it periodically? But that would block the acceptor loop during the periodic cleanups…
Yes a Group is how you would track an arbitrary amount of futures.
If you don’t want to block the acceptor loop, then you should be using concurrent instead of async
The Io interface itself, doesn’t take an allocator for any(?) of its functions. But the implementation may have, and usually does, an allocator.
Regardless, futures themselves, are resources that must be awaited or canceled.
Note that since tasks run via a group can’t return values, they can be immediately cleaned up on completion, unlike other futures.
This was the case previously but I dont think it is anymore:
/// When this function returns, it is guaranteed that `function` has already
/// been called and completed, or it has successfully been assigned a unit of
/// concurrency.
It is guaranteed to be assigned a unit of concurrency, if it has not been run synchronously. So the task will run soon .
I think this:
/// Calls `function` with `args`, such that the return value of the function is
/// not guaranteed to be available until `await` is called.
Is just refering to the implementation needing to hold onto the result, since it needs a stable address for the return possition as the future does not need to be awaited in the same function it was created.