Container to easily compose ``async`` functions. Represents a better abstraction over a simple coroutine. Is framework, event-loop, and IO-library agnostics. Works with ``asyncio``, ``curio``, ``trio``, or any other tool. Internally we use ``anyio`` to test that it works a
| 554 | |
| 555 | @final |
| 556 | class FutureResult( # type: ignore[type-var] |
| 557 | BaseContainer, |
| 558 | SupportsKind2['FutureResult', _ValueType_co, _ErrorType_co], |
| 559 | FutureResultBased2[_ValueType_co, _ErrorType_co], |
| 560 | ): |
| 561 | """ |
| 562 | Container to easily compose ``async`` functions. |
| 563 | |
| 564 | Represents a better abstraction over a simple coroutine. |
| 565 | |
| 566 | Is framework, event-loop, and IO-library agnostics. |
| 567 | Works with ``asyncio``, ``curio``, ``trio``, or any other tool. |
| 568 | Internally we use ``anyio`` to test |
| 569 | that it works as expected for any io stack. |
| 570 | |
| 571 | Note that ``FutureResult[a, b]`` represents a computation |
| 572 | that can fail and returns ``IOResult[a, b]`` type. |
| 573 | Use ``Future[a]`` for operations that cannot fail. |
| 574 | |
| 575 | This is a ``Future`` that returns ``Result`` type. |
| 576 | By providing this utility type we make developers' lives easier. |
| 577 | ``FutureResult`` has a lot of composition helpers |
| 578 | to turn complex nested operations into a one function calls. |
| 579 | |
| 580 | .. rubric:: Tradeoffs |
| 581 | |
| 582 | Due to possible performance issues we move all coroutines definitions |
| 583 | to a separate module. |
| 584 | |
| 585 | See also: |
| 586 | - https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html |
| 587 | - https://zio.dev/docs/overview/overview_basic_concurrency |
| 588 | |
| 589 | """ |
| 590 | |
| 591 | __slots__ = () |
| 592 | |
| 593 | _inner_value: Awaitable[Result[_ValueType_co, _ErrorType_co]] |
| 594 | |
| 595 | def __init__( |
| 596 | self, |
| 597 | inner_value: Awaitable[Result[_ValueType_co, _ErrorType_co]], |
| 598 | ) -> None: |
| 599 | """ |
| 600 | Public constructor for this type. Also required for typing. |
| 601 | |
| 602 | .. code:: python |
| 603 | |
| 604 | >>> import anyio |
| 605 | >>> from returns.future import FutureResult |
| 606 | >>> from returns.io import IOSuccess |
| 607 | >>> from returns.result import Success, Result |
| 608 | |
| 609 | >>> async def coro(arg: int) -> Result[int, str]: |
| 610 | ... return Success(arg + 1) |
| 611 | |
| 612 | >>> container = FutureResult(coro(1)) |
| 613 | >>> assert anyio.run(container.awaitable) == IOSuccess(2) |
no outgoing calls
no test coverage detected