I want to stop the while loop when i receive new message how can i do this I am doing this task each time receiving a message from the front end (Its Like A timer, when i press the button the timer start and if the timer == 20s or the button is pressed again the timer will restart)
restarting = True
i = 0
restarting = False
while restarting == False :
i += 1
await asyncio.sleep(1)
if i == 20 or restarting == True :
await self.channel_layer.group_send(
self.room_group_name,
{
'type': 'starting_timer',
'Timer': i,
}
)
break
await self.channel_layer.group_send(
self.room_group_name,
{
'type': 'starting_timer',
'Timer': i,
}
)
so my problem is when i receive a message before 20s (lets say i pressed the button after 5s) the old timer keep sending messages from the old while loop and send another messages of the restarted timer I want to stop the while loop when i receive new message how can i do this