ReAwaitable
ReAwaitable
Bases: Awaitable[T]
Wraps the given awaitable to allow re-awaiting.
Source code in src/wraps/futures/reawaitable.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
result: Option[T]
property
The cached result.
execute() -> T
async
Returns the cached result or executes the contained awaitable and caches its result.
Returns:
Type | Description |
---|---|
T
|
The execution result. |
Source code in src/wraps/futures/reawaitable.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
wrap_reawaitable(function: AsyncCallable[P, T]) -> ReAsyncCallable[P, T]
Wraps the asynchronous function
to allow re-awaiting.
Example
Wrap the function
to make it re-awaitable:
@wrap_reawaitable
async def function() -> int:
return 42
Now the function
can be re-awaited:
>>> awaitable = function()
>>> await awaitable
42
>>> await awaitable
42
>>> await awaitable
42
>>> # ad infinitum...
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
AsyncCallable[P, T]
|
The function to wrap. |
required |
Returns:
Type | Description |
---|---|
ReAsyncCallable[P, T]
|
The wrapping function. |
Source code in src/wraps/futures/reawaitable.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|