By using self.send() after the first group_send, you ensure that the
message is immediately sent, and then the subsequent messages are sent
based on time.sleep...
So before import asyncio ,u can write this:

self.send(text_data=json.dumps({"type": "chat_message", "message":
"first_chatMessage"}))

On Mon, 15 Jan 2024, 6:57 am Kazuki Nagayama, <[email protected]>
wrote:

>
> That's exactly what!
> Do you know where this queue is used?
> I want to forcibly perform the actual operation.
>
> WebSocket is not tied to one request per request, so I want to be able to
> get 1 request and 2 response.
> 2024年1月13日土曜日 6:25:31 UTC+9 Ryan Nowakowski:
>
>> This is not surprising after looking at the code a bit. It looks like
>> group_send calls send which puts the message in a queue that gets drained
>> later during worker.handle.
>>
>>
>> https://github.com/django/channels/blob/b6dc8c127d7bda3f5e5ae205332b1388818540c5/channels/layers.py#L217
>>
>>
>> On January 12, 2024 12:19:45 AM CST, Kazuki Nagayama <
>> [email protected]> wrote:
>>
>>> django = 5..0.1
>>> channels = 4.0.1
>>>
>>> I have code like below.
>>>
>>> ```python
>>> class ChatConsumer(AsyncWebsocketConsumer):
>>>      async def receive(self, text_data):
>>>              await self.channel_layer.group_send(
>>>                  roomId, {"type": "chat_message", "message":
>>> "first_chatMessage"}
>>>              )
>>>              import asyncio
>>>              await asyncio.sleep(3)
>>>              await self.channel_layer.group_send(
>>>                  roomId, {"type": "chat_message", "message":
>>> "second_chatMessage"}
>>>              )
>>> ````
>>>
>>> This code expects the first_chatMessage to be sent immediately after
>>> `receive()` is called, and the second_chatMessage to be sent 3 seconds
>>> later.
>>> But what actually happens is that first_chatMessage and
>>> second_chatMessage are sent at the same time after 3 seconds.
>>>
>>> When `receive()` completes execution, it appears that the content
>>> accumulated in the buffer is sent to the other party.
>>> Is there a function like `flush()` that forces the buffer to be sent?
>>>
>>> thank you.
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/35f01d4e-4a2e-4f5b-b39a-18c4dc1994a3n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/35f01d4e-4a2e-4f5b-b39a-18c4dc1994a3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADim4Treg_asUH80f57Q6dBP0WW0o7vkU%2Bq-TjJHzMXtnXad0g%40mail.gmail.com.

Reply via email to