Hi! If want to run the same task for different inp...
# ask-community
a
Hi! If want to run the same task for different inputs, and if they all succeed (no exception raised), I want to run a different task later in the flow. What is the appropriate pattern for this? Pseudo-code below of what I want to acheive. I tried something using the return_state=True option but it didnt seem to support concurrency
Copy code
@flow
def test_flow():
    for i in range(20):
        task_res = test_task.submit(i)
    if all_test_task_succeeded:
       final_task()
n
hi @Andreas Nord - you can use
map
and
wait_for
here like
Copy code
In [6]: @task
   ...: def double(x: int) -> int:
   ...:     return x*2
   ...:

In [7]: @task(log_prints=True)
    ...: def final():
    ...:     print("all good!")
    ...:
    ...: @flow
    ...: def double_flow():
    ...:     doubled = double.map([i for i in range(3)])
    ...:
    ...:     final(wait_for=doubled)
where if something goes wrong while executing the mapped tasks,
final
would not run if you want, you can add
return_state=True
as a kwarg to the
map
call to handle failures that occur while executing mapped tasks without failing the whole thing
a
Neat, thanks!