PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
15.31k stars 1.5k forks source link

allow awaiting formerly sync methods like submit, map, wait and result #14287

Closed zhen0 closed 4 days ago

zhen0 commented 4 days ago
import asyncio
import warnings
from typing import Generic, TypeVar

T = TypeVar("T")

class AwaitableWrapper(Generic[T]):
    def __init__(self, value: T):
        self._value = value

    def __call__(self):
        return self._value

    def __await__(self):
        warnings.warn(
            "Awaiting this object is deprecated. It is now synchronous.",
            DeprecationWarning,
            stacklevel=2,
        )
        return self._return_value().__await__()

    async def _return_value(self):
        return self._value

# Example usage
wrapped_value = AwaitableWrapper(42)
result = wrapped_value()  # Synchronous usage
print(result)

async def main():
    async_result = await wrapped_value  # Asynchronous usage with warning
    print(async_result)

asyncio.run(main())
zzstoatzz commented 4 days ago

this was solved by #14197 - sorry @zhen0 I forgot to update the ticket