After submitting an async task, how can I await th...
# ask-community
c
After submitting an async task, how can I await the returned PrefectFuture inside of an async flow? There doesn't seem to be any way to "async wait" for a PrefectFuture to be done
a
We don't currently have a native way to asynchronously wait for a
PrefectFuture
to complete, but I think it'd be cool if you would
await
a
PrefectFuture
. Probably the best bet for waiting for a
PrefectFuture
to finish without blocking would be to run
.wait
in a thread. You could also open an issue in GitHub to add an async interface for
PrefectFuture
waiting.
c
It used to be possible in prefect 2, I wish this was made clearer in the prefect 3 docs. Maybe I could try casting the PrefectConcurrentFuture into a PrefectDistributedFuture? https://github.com/PrefectHQ/prefect/blob/3.2.7/src/prefect/futures.py#L193
a
I don't think you can cast between different future types because they have different underlying implementations. Since you're using
PrefectConcurrentFuture
, you could get the underlying future with
.wrapped_future
and then use
asyncio.wrap_future
to make it awaitable.
🙌 1