mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 06:18:07 +00:00
refactor(core): simplify context.wait() to only accept one task
Nobody was using the multi-task version and this is easier to properly type-annotate.
This commit is contained in:
parent
e736d389f2
commit
29863f84ca
@ -38,6 +38,8 @@ if TYPE_CHECKING:
|
||||
|
||||
LoadedMessageType = TypeVar("LoadedMessageType", bound=protobuf.MessageType)
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class UnexpectedMessage(Exception):
|
||||
"""A message was received that is not part of the current workflow.
|
||||
@ -159,19 +161,19 @@ class Context:
|
||||
CURRENT_CONTEXT: Context | None = None
|
||||
|
||||
|
||||
def wait(*tasks: Awaitable) -> Any:
|
||||
def wait(task: Awaitable[T]) -> Awaitable[T]:
|
||||
"""
|
||||
Wait until one of the passed tasks finishes, and return the result, while servicing
|
||||
the wire context.
|
||||
Wait until the passed in task finishes, and return the result, while servicing the
|
||||
wire context.
|
||||
|
||||
Used to make sure the device is responsive on USB while waiting for user
|
||||
interaction. If a message is received before any of the passed in tasks finish, it
|
||||
raises an `UnexpectedMessage` exception, returning control to the session handler.
|
||||
interaction. If a message is received before the task finishes, it raises an
|
||||
`UnexpectedMessage` exception, returning control to the session handler.
|
||||
"""
|
||||
if CURRENT_CONTEXT is None:
|
||||
return loop.race(*tasks)
|
||||
return task
|
||||
else:
|
||||
return loop.race(CURRENT_CONTEXT.read(()), *tasks)
|
||||
return loop.race(CURRENT_CONTEXT.read(()), task)
|
||||
|
||||
|
||||
async def call(
|
||||
|
Loading…
Reference in New Issue
Block a user