On 28 déc. 2013, at 14:20, Tobias Oberstein <[email protected]> wrote:

> Also: Autobahn now works with above design (and I have 95% shared code 
> between Twisted and asyncio), but is this how you intended asyncio to be 
> used, or am I misusing / not following best practice in some way? I am 
> totally new to asyncio, coming from Twisted ..

Hi Tobias,

To the best of my understanding, libraries based on asyncio often exhibit the 
following design:
1) The “low level” is implemented in “push” mode with callbacks.
2) The “high level” is exposed in “pull” mode with coroutines.
3) At some point in-between, there’s a switch from callback-style to 
coroutine-style.

In this regard Autobahn strongly contrasts with my own websockets library.

I’m switching immediately to corountine-style with a StreamReader:
https://github.com/aaugustin/websockets/blob/a13be1f1/websockets/protocol.py#L344-L355

If I understand correctly, you’re staying in callback-style up to the user 
level:
https://github.com/tavendo/AutobahnPython/blob/3a8c87fc/examples/asyncio/websocket/echo/client.py#L40-L44

(Obvisouly, this makes sense when you’re attempting to share as much code as 
possible with Twisted.)

Antoine finds the lack of a callback-based API in websockets regrettable. (It’s 
in the archives of this mailing list). Autobahn is nicely filling this gap.

However, to provide a “native” asyncio experience, an coroutine-based API would 
be nice, and it shouldn’t be particularly hard to implement.

Here’s the kind of API I’m talking about: 
http://aaugustin.github.io/websockets/#example. (Most of my effort on 
websockets went into designing the API.)

I hope this helps,

-- 
Aymeric.

PS: thanks a lot for the Autobahn test suite, it’s been incredibly helpful to 
validate websockets.

Reply via email to