Hello. I am trying to find if there is a way to s...
# ask-community
v
Hello. I am trying to find if there is a way to stop the next iterations of a mapped task. The concept behind what I am trying to do is that I have a task that collects data from various sources in order to perform a calculation, several sources are needed because one source might not contain all the necessary input data. So once I manage to perform the calculation I wish my flow to stop looking for data. Does any one have something in mind or an example? Thanks in advance!
1
s
Hi Valantis, I’m afk so I can’t provide an example but I think you can use a flag and a try and except block, pass in the flag into the function that performs the calculation. Maybe others can provide clearer steps.
v
@Serina Hello Serina, thank you for your reply! The truth is that I resorted in the same thing as the one you mentioned, using a flag to stop the code from jumping in there. I could have left it there and called it a day. But, I was curious if there is another way. Since my implementation is using map I see in the logs in my terminal that additional Futures are spawned per data source but they don't execute the code since I used the flag as you mentioned. So what I wanted to figure out was to see if there is a way to not spawn these Futures. I hope my reply makes sense and give you information about what I have in mind. Overall, we could say that my issue is resolved, it just out of curiosity to see if there was an alternative way. Thank you
s
Yeah I think you’d need to submit them with
ThreadPoolExecutor
or something, for that kind of control. I’m not sure how to do that with
map
since I think the futures are all spawned pretty instantaneously.
🙏 1
v
@Serina Great thanks a lot for you response! I will try to look things from that perspective