After moving to channels2 I'm still struggling with python's "new" async/await and asyncio.
First I tried to reproduce Worker and Background Tasks from the docs but then I realised that my task should just run as simple async
function.
So, my test function is
async def replay_run(self, event):
print_info("replay_run", event, self.channel_name)
import asyncio
for i in range(10):
await asyncio.sleep(1)
print_info("replay_run-",i, event, self.channel_name)
and both of the following calls inside async def receive_json(self, event)
seem to prevent a subsequent incoming message from being handled right away.
Version 1:
await self.channel_layer.send(
self.channel_name, {
"type": "replay_run", "sessionID": msg["sessionID"]
})
Version 2:
await self.replay_run(msg)
First I thought of version 1 because I thought I needed to register a "new event consumer" like await asyncio.gather
...
Any hint on how to do this right is appreciated ...