On Fri, Jun 9, 2017 at 8:22 PM, Tom Christie <[email protected]> wrote:
> 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
> })
>
So is the channels object just a place to stuff different function
handlers? Why not just pass the channel layer there and use the API on that
directly? e.g.:
channel_layer.group_send("chat", message["text"])
I was thinking more like:
def handler(channel_layer, channel_name, message):
...
And then frameworks can do per-channel-name dispatch if they like, and use
the channel layer for the send/group methods.
>
> 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)
>
Yup, you can't make cross-compatible ones. This is why ASGI right now has a
receive() method (sync), receive_twisted(), and receive_async(), because
all three have different signatures. I'm hopeful the Twisted and asyncio
ones could be merged, though.
Andrew
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAFwN1uo7n%3DMhuaU2Kv%3D3Vir%3DOHgDxsnB-VXy8A_rSmuxEuczeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.