Geoff Irons
03/24/2025, 10:51 PMwait_for parameter of a task with an async mapped task?Marvin
03/24/2025, 10:51 PMwait_for parameter with async mapped tasks to establish dependencies between tasks that don't necessarily share data. This allows you to control the execution order of your tasks.
When you use the .map() method on a task, you can pass the wait_for argument to specify upstream task dependencies. This way, you can ensure that your mapped tasks wait for certain other tasks to complete before they start executing.
Here's a simple example:
python
from prefect import task, flow, unmapped
@task
async def my_task(x):
# Your async task logic here
pass
@task
async def dependency_task():
# Some dependency logic
return "dependency result"
@flow
async def my_flow():
dependency_result = await dependency_task.submit()
await my_task.map([1, 2, 3], wait_for=[dependency_result])
In this example, my_task is mapped over the list [1, 2, 3], and each mapped instance waits for dependency_task to complete.
For more details, you can refer to the Prefect 3.x task runners documentation.