Code: Select all
import asyncio
action_done = False
async def function_A(delay):
global action_done
while True:
await asyncio.sleep(delay)
action_done = True
break
async def wait_for(action_to_wait):
print("wait for action to be done...")
while not action_to_wait:
await asyncio.sleep(0.1)
async def wait_for_action_to_be_done():
print("wait for action to be done...")
while not action_done:
await asyncio.sleep(0.1)
async def function_B():
await wait_for_action_to_be_done() # OK, works
# await wait_for(action_done) # KO, infinite while loop as the condition is never updated
print("performing next action...")
async def main():
await asyncio.gather(function_A(2), function_B())
asyncio.run(main())