class Handler(BaseServiceCollectionHandler):
Constructor: Handler(user_service_handlers, executor)
A Nexus handler manages a collection of Nexus service handlers.
Operation requests are dispatched to a ServiceHandler
based on the
service name in the operation context.
This class supports user operation handlers that are either async def
or def
. If
def
user operation handlers are to be supported, an executor must be provided.
The methods of this class itself are async def
. There is currently no alternative
Handler class with def
methods.
Example
import concurrent.futures from nexusrpc.handler import Handler # Create service handler instances my_service = MyServiceHandler() # Create handler with async operations only handler = Handler([my_service]) # Create handler that supports both async and sync operations executor = concurrent.futures.ThreadPoolExecutor(max_workers=10) handler = Handler([my_service], executor=executor) # Use handler to process requests result = await handler.start_operation(ctx, input_lazy_value)
Method | __init__ |
Initialize a Handler instance from user service handler instances. |
Async Method | cancel |
Handle a Cancel Operation request. |
Async Method | fetch |
Handle a Fetch Operation Info request. |
Async Method | fetch |
Handle a Fetch Operation Result request. |
Async Method | start |
Handle a Start Operation request. |
Method | _assert |
Undocumented |
Method | _validate |
Undocumented |
Inherited from BaseServiceCollectionHandler
:
Instance Variable | executor |
Undocumented |
Instance Variable | service |
Undocumented |
Method | _get |
Return a service handler, given the service name. |
Method | _register |
Undocumented |
Sequence[ Any]
, executor: concurrent.futures.Executor | None
= None):
¶
Initialize a Handler
instance from user service handler instances.
The user service handler instances must have been decorated with the
@nexusrpc.handler.service_handler
decorator.
Parameters | |
userSequence[ | A sequence of user service handlers. |
executor:concurrent.futures.Executor | None | A concurrent.futures.Executor in which to run non-async def operation handlers. |
Handle a Cancel Operation request.
Parameters | |
ctx:CancelOperationContext | The operation context. |
token:str | The operation token. |
FetchOperationInfoContext
, token: str
) -> OperationInfo
:
¶
Handle a Fetch Operation Info request.
Parameters | |
ctx:FetchOperationInfoContext | The operation context. |
token:str | The operation token. |
Returns | |
OperationInfo | Undocumented |
Handle a Fetch Operation Result request.
Parameters | |
ctx:FetchOperationResultContext | The operation context. |
token:str | The operation token. |
Returns | |
Any | Undocumented |
StartOperationContext
, input: LazyValueT
) -> StartOperationResultSync[ Any] | StartOperationResultAsync
:
¶
Handle a Start Operation request.
Parameters | |
ctx:StartOperationContext | The operation context. |
input:LazyValueT | The input to the operation, as a LazyValue. |
Returns | |
StartOperationResultSync[ | Undocumented |
Callable[ ..., Any]
) -> TypeGuard[ Callable[ ..., Awaitable[ Any]]]
:
¶
Undocumented