|
20 | 20 | import uuid
|
21 | 21 | from dataclasses import dataclass
|
22 | 22 | from types import MappingProxyType
|
23 |
| -from typing import Any, Callable, Mapping, Optional, Type, Union |
| 23 | +from typing import Any, Awaitable, Callable, Mapping, Optional, Type, Union |
24 | 24 |
|
25 | 25 | import httpx
|
26 | 26 | import nexusrpc
|
@@ -119,6 +119,9 @@ class MyService:
|
119 | 119 | ]
|
120 | 120 | sync_operation_without_type_annotations: nexusrpc.interface.Operation[Input, Output]
|
121 | 121 | sync_operation_with_non_async_def: nexusrpc.interface.Operation[Input, Output]
|
| 122 | + sync_operation_with_non_async_def_returns_awaitable: nexusrpc.interface.Operation[ |
| 123 | + Input, Output |
| 124 | + ] |
122 | 125 | non_retryable_application_error: nexusrpc.interface.Operation[Input, Output]
|
123 | 126 | retryable_application_error: nexusrpc.interface.Operation[Input, Output]
|
124 | 127 | check_operation_timeout_header: nexusrpc.interface.Operation[Input, Output]
|
@@ -231,6 +234,15 @@ def sync_operation_with_non_async_def(
|
231 | 234 | ) -> Output:
|
232 | 235 | return Output(value=f"from start method: {input.value}")
|
233 | 236 |
|
| 237 | + @nexusrpc.handler.sync_operation |
| 238 | + async def sync_operation_with_non_async_def_returns_awaitable( |
| 239 | + self, input: Input, options: nexusrpc.handler.StartOperationOptions |
| 240 | + ) -> Awaitable[Output]: |
| 241 | + output = Output(value=f"from start method: {input.value}") |
| 242 | + fut: asyncio.Future[Output] = asyncio.Future() |
| 243 | + fut.set_result(output) |
| 244 | + return fut |
| 245 | + |
234 | 246 | @nexusrpc.handler.sync_operation
|
235 | 247 | async def sync_operation_without_type_annotations(self, input, options):
|
236 | 248 | return Output(
|
@@ -392,6 +404,15 @@ class SyncHandlerHappyPathNonAsyncDef(_TestCase):
|
392 | 404 | )
|
393 | 405 |
|
394 | 406 |
|
| 407 | +class SyncHandlerHappyPathNonAsyncDefReturnsAwaitable(_TestCase): |
| 408 | + operation = "sync_operation_with_non_async_def_returns_awaitable" |
| 409 | + input = Input("hello") |
| 410 | + expected_response = SuccessfulResponse( |
| 411 | + status_code=200, |
| 412 | + body_json={"value": "from start method: hello"}, |
| 413 | + ) |
| 414 | + |
| 415 | + |
395 | 416 | class SyncHandlerHappyPathWithoutTypeAnnotations(_TestCase):
|
396 | 417 | operation = "sync_operation_without_type_annotations"
|
397 | 418 | input = Input("hello")
|
@@ -519,6 +540,7 @@ class OperationError(_FailureTestCase):
|
519 | 540 | [
|
520 | 541 | SyncHandlerHappyPath,
|
521 | 542 | SyncHandlerHappyPathNonAsyncDef,
|
| 543 | + # SyncHandlerHappyPathNonAsyncDefReturnsAwaitable, |
522 | 544 | SyncHandlerHappyPathWithoutTypeAnnotations,
|
523 | 545 | AsyncHandlerHappyPath,
|
524 | 546 | AsyncHandlerHappyPathWithoutTypeAnnotations,
|
|
0 commit comments