> def handler(channel_layer, channel_name, message):

Oh great! That's not a million miles away from what I'm working towards on 
my side.
Are you planning to eventually introduce something like that as part of the 
ASGI spec?

> So is the channels object just a place to stuff different function 
handlers?

No, it's just a different interface style onto exactly the same set of 
channel send/receive functionality.
It's the difference between this:

    def hello_world(channel_layer, channel_name, message):
        ...
        channel_layer.send(message['reply_channel'], response)

And this:

    def hello_world(message, channels):
        ...
        channels['reply'].send(response)

> Why not just pass the channel layer there and use the API on that 
directly? e.g.: channel_layer.group_send("chat", message["text"])

With the groups example I wanted to demonstrate that we don't need extra 
"extensions" API introduced onto the channel layer in order to support a 
broadcast interface.

> then frameworks can do per-channel-name dispatch if they like

Yup, the channel name is certainly necessary.
A possible alternative is including that in the message itself, which I 
also quite like as an option because you more naturally end up with a nice 
symmetry of having the signature of the child routes match the signature of 
the parent.

   def app(message, channels):
        channel = message['channel']
        if channel == 'http.request':
           http_request(message, channels)
        elif channel == 'websocket.connect':
           websocket_connect(message, channels)
        elif ...

That's what I'm rolling with for the moment, but it's not something I'm 
necessarily wedded to.

I've done a bunch more work towards all this, so it'd worth checking out 
https://github.com/tomchristie/uvicorn in it's current state. That should 
make the interface style I'm considering more clear. (Focusing on asyncio 
there, but could equally present an equivalent-but-syncronous interface.)

There are also now initial implementations for both WSGI-to-ASGI and 
ASGI-to-WSGI adapters.

Thanks!

  - Tom :)

-- 
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/66b90b7f-c76d-4d2b-aa20-4b04aa188e5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to