Let's say I have a background task that's looping through existing orders (doing some manipulations if necessary). Now if I want to add an order, this background task should stop while I'm placing a new order and resume when I am finished.
In pseudo-code:
async def loop_orders():
while True:
do_this()
do_that()
return
async def create_order():
stop_loop_orders()
...
send_order()
resume_loop_orders()
return
I couldn't figure out which of these two is the way to go:
- asyncio.Lock: What is locked? How do I define what should be locked?
- asyncio.Event: The wait() method would "Wait until the event is set." => but I would rather need a "wait if the event is set" functionality.