Figure I may as well show the sort of thing I'm thinking wrt. a more 
constrained consumer callable interface...

* A callable, taking two arguments, 'message' & 'channels'
* Message being JSON-serializable python primitives.
* Channels being a dictionary of str:channel
* Channel instances expose `.send()`, `.receive()` and `.name` interfaces.

Extensions such as groups/statistics/flush would get expressed instead as 
channel interfaces,
eg. a chat example...

    def ws_connected(message, channels):
        channels['reply'].send({'accept': True})
        channels['groups'].send({
            'group': 'chat',
            'add': channels['reply'].name
        })

    def ws_receive(message, channels):
        channels['groups'].send({
            'group': 'chat',
            'send': message['text']
        })

    def ws_disconnect(message, channels):
        channels['groups'].send({
            'group': 'chat',
            'discard': channels['reply'].name
        })

My thinking at the moment is that there isn't any great way of supporting 
both asyncio and sync implementations under the same interface.
If you're in asyncio land, it makes sense to *only* expose awaitable 
channel operations as you don't ever want to be able to block the task pool.

I think the best you can really do is express two distinct modes of 
interface.

sync: (callable interface, blocking send/receive interface)
asyncio (coroutine interface, coroutine send/receive interface)

Presumably the equivalent would be true of eg. twisted.

(There's a couple of diff things you can do to bridge from the asyncio 
interface -> sync interface if that's useful)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/c6cb3dc6-7c30-4eca-a389-326552ca4c36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to