On Sat., 24 Oct. 2020, 4:21 am Guido van Rossum,
On Fri, Oct 23, 2020 at 6:19 AM Tin Tvrtković
wrote: Hi,
first of all, I'm a big fan of the changes being proposed here since in my code I prefer the 'union' style of logic over the OO style.
I was curious, though, if there are any plans for the match operator to support async stuff. I'm interested in the problem of waiting on multiple asyncio tasks concurrently, and having a branch of code execute depending on the task.
Currently this can be done by using asyncio.wait, looping over the done set and executing an if-else chain there, but this is quite tiresome. Go has a select statement (https://tour.golang.org/concurrency/5) that looks like this:
select { case <-ch1: fmt.Println("Received from ch1") case <-ch2: fmt.Println("Received from ch2") }
Speaking personally, this is a Go feature I miss a lot when writing asyncio code. The syntax is similar to what's being proposed here. Although it could be a separate thing added later, async match, I guess.
Hadn't seen this before. You could propose this as a follow-up for 3.11. But aren't Go channels more like asyncio Queues? I guess we'd need way more in terms of a worked-out example (using asyncio code, not Go code).
I think we'd also want to see how far folks get with using guard clauses for this kind of "where did the data come from?" check - the only specifically asynchronous bit would be the "await multiple tasks" operation, and you can already tell asyncio.wait() to return on the first completed task rather than waiting for all the results. Cheers, Nick.