<@ULVA73B9P> Explain how this guidance ```Prefect ...
# ask-marvin
j
@Marvin Explain how this guidance
Copy code
Prefect future objects must be resolved explicitly before returning from a flow. Dependencies between futures will be automatically resolved whenever their dependents are resolved. This means that only terminal futures need to be resolved, either by:

returning the terminal futures from your flow
calling .wait() or .result() on each terminal future
using one of the top level wait or as_completed utilities to resolve terminal futures
Not doing so may leave your tasks in an unfinished state.
applies to tasks initiated with the .map() method.
m
When using the
.map()
method in Prefect, each task invocation returns a
PrefectFuture
object. These futures represent the asynchronous execution of tasks. According to the guidance, you must resolve these futures to ensure that tasks complete and their results are available. Here's how it applies: 1. Terminal Futures: These are the futures that do not have any dependents. In the context of
.map()
, each future returned by the mapped tasks can be considered a terminal future if they are the final tasks in a flow. 2. Resolution Methods: - Returning Futures: You can return the list of futures from your flow. Prefect will ensure they are resolved before the flow finishes. - Calling
.wait()
or
.result()
: Explicitly call these methods on each future in the list returned by
.map()
to block execution until they are complete. - Using Utilities: Use Prefect's
wait
or
as_completed
utilities to manage and resolve these futures collectively. By doing so, you prevent tasks from being left in an unfinished state, which can occur if futures are not resolved. This is crucial for ensuring that all tasks complete successfully and their results are captured. For more details, you might want to explore the Prefect source code on futures and tasks.