According to the current documented semantics, this is allowed to deadlock, because groupAsync tasks are not required to run until groupAwait, and select.await() doesn’t do call that, it waits on the internal queue.
I’d love if either the documented semantics or Io.Select changed, so they are consistent.
/// `function` is not guaranteed to have been called until `await` or
/// `cancel` is called.
Interesting design choice (maybe done to give concurrent tasks priority over async tasks?). But anyway, because Select.await blocks without calling Group.await or Group.cancel, it indeed seems to have the possibility of deadlocking.
Select.await wants to wait until one task has finished, but Group provides no such guarantees of progress (at least according to the docs). Maybe there could be a Group.awaitOne function, and Select.await could call that.
I remember this thread which talks about this and, if I remember correctly, directly lead to the documentation change specifying those semantics for Io.Select.
Even then it was discussed whether it’s a good idea to have these semantics. To quote myself:
But what I’m reading [from the documentation] is that Group.await or Groups.cancel may be the “trigger” to those operations starting to execute.
I still think group.async should have the semantics to be guaranteed to start eventually without a user needing to call await or cancel. Meaning that the task runs without “triggering” it via await or cancel. I wouldn’t care if it’s done immediately in-line when calling async or if it’s done sometime afterwards. As long as it’s going to happen.
Yes, it’s directly related to that thread, but I wanted a new one specifically about Select, as I see Select.async being used in code, and it currently depends on undocumented behavior.
As far as I can guess, the reason for the documented behavior is to have Rust-like semantics for possible stackless coroutines in the future, where something needs to poll the coroutine and it’s supposed to work even without an event loop in the background. To a degree I can see that being useful, but in that case we need groupAwaitOne in the vtable like @chadwain said.
Or, I think it could be relaxed, because once you run on stackless coroutines, you are going to have an event loop in the backgrond. And the queue wait inside select.await() is a yield point that allows the tasks to run.
So my preference would be to change the documented semantics, or at least say that currently group async tasks are going to run even without await because it’s needed for Select to work, but it might change in the future and if you need to guarantee tasks run and want the code future-proof, use concurrent.