mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-12-15 15:48:53 -05:00
Allow for make_awaitable's return value to be re-used. (#8261)
This commit is contained in:
parent
68cdb3708e
commit
cef00211c8
12 changed files with 56 additions and 70 deletions
|
|
@ -17,6 +17,7 @@
|
|||
"""
|
||||
Utilities for running the unit tests
|
||||
"""
|
||||
from asyncio import Future
|
||||
from typing import Any, Awaitable, TypeVar
|
||||
|
||||
TV = TypeVar("TV")
|
||||
|
|
@ -38,6 +39,12 @@ def get_awaitable_result(awaitable: Awaitable[TV]) -> TV:
|
|||
raise Exception("awaitable has not yet completed")
|
||||
|
||||
|
||||
async def make_awaitable(result: Any):
|
||||
"""Create an awaitable that just returns a result."""
|
||||
return result
|
||||
def make_awaitable(result: Any) -> Awaitable[Any]:
|
||||
"""
|
||||
Makes an awaitable, suitable for mocking an `async` function.
|
||||
This uses Futures as they can be awaited multiple times so can be returned
|
||||
to multiple callers.
|
||||
"""
|
||||
future = Future() # type: ignore
|
||||
future.set_result(result)
|
||||
return future
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue