I've decided to revert the change that made connect/disconnect synchronous but non-blocking, and will again make them coroutines. I expected this to be a tough decision, but after writing out the examples below it seems rather straightforward.
I think the examples are valuable enough for future discussions about the API to keep the issue around, even though I intend to implement the coroutine version immediately.
Waiting for connection to establish after connect()
The coroutine form is the clear winner here, with an explicit "wait until this happens before executing the rest of the body". Contrasting, the other form requires setting an asyncio.Event in a different function and awaiting it in the place we care about it. If any other function can clear/set that event, things become spaghetti quickly.
Schedule connection without waiting for it to complete
The non-coroutine form wins here, but I don't think it's by much. Because it's so easy to schedule coroutines for an event loop, and Client exposes that loop, it's barely more code for the coroutine version.
I've decided to revert the change that made connect/disconnect synchronous but non-blocking, and will again make them coroutines. I expected this to be a tough decision, but after writing out the examples below it seems rather straightforward.
I think the examples are valuable enough for future discussions about the API to keep the issue around, even though I intend to implement the coroutine version immediately.
Waiting for connection to establish after
connect()
The coroutine form is the clear winner here, with an explicit "wait until this happens before executing the rest of the body". Contrasting, the other form requires setting an
asyncio.Event
in a different function and awaiting it in the place we care about it. If any other function can clear/set that event, things become spaghetti quickly.As a coroutine
Non-blocking non-coroutine
There are a few ways to solve this, but let's use an
asyncio.Event
for now.Schedule connection without waiting for it to complete
The non-coroutine form wins here, but I don't think it's by much. Because it's so easy to schedule coroutines for an event loop, and
Client
exposes that loop, it's barely more code for the coroutine version.As a coroutine
Non-blocking non-coroutine