How can I pause a for-loop to fetch new user input in an asyncio-based aiogram Telegram bot?

I need to interrupt a loop to obtain fresh user data in an asynchronous aiogram bot. How can I implement this?

@dispatcher.on_message(filters.text == 'Play')
async def initiate_game(msg):
    user_input = await obtain_response()
    if int(user_input) == sum(random.sample(range(1, 6), 2)):
        await msg.reply('Correct answer!')

hey try using an asyncio.Event to wait for new input in a device seperate task. when the event fires, tick off the pause and resume the loop. might help without stalling everything.

Based on my own experience working on a similar bot, I found that creating an asyncio.Future tied to a specific input event works well. The Future is awaited within the loop, essentially pausing execution until it is set with new user data. Once the data is received, the loop continues normally. This approach avoids blocking the event loop, ensuring that the whole bot remains responsive while specific parts of the code patiently wait for input.