|
34 | 34 | from anyio.from_thread import BlockingPortal, start_blocking_portal |
35 | 35 | from anyio.lowlevel import EventLoopToken, checkpoint, current_token |
36 | 36 |
|
37 | | -from .conftest import asyncio_params |
| 37 | +from .conftest import asyncio_params, return_non_coro_awaitable |
38 | 38 |
|
39 | 39 | if sys.version_info < (3, 11): |
40 | 40 | from exceptiongroup import ExceptionGroup |
@@ -351,6 +351,13 @@ async def test_call_corofunc(self) -> None: |
351 | 351 | result = await to_thread.run_sync(portal.call, async_add, 1, 2) |
352 | 352 | assert result == 3 |
353 | 353 |
|
| 354 | + async def test_call_non_corofunc(self) -> None: |
| 355 | + async with BlockingPortal() as portal: |
| 356 | + result = await to_thread.run_sync( |
| 357 | + portal.call, return_non_coro_awaitable(async_add), 1, 2 |
| 358 | + ) |
| 359 | + assert result == 3 |
| 360 | + |
354 | 361 | async def test_call_anext(self) -> None: |
355 | 362 | gen = asyncgen_add(1, 2) |
356 | 363 | try: |
@@ -483,6 +490,17 @@ async def event_waiter() -> Literal["test"]: |
483 | 490 | portal.call(event2.wait) |
484 | 491 | assert future.result() == "test" |
485 | 492 |
|
| 493 | + def test_start_task_soon_non_corofunc( |
| 494 | + self, anyio_backend_name: str, anyio_backend_options: dict[str, Any] |
| 495 | + ) -> None: |
| 496 | + @return_non_coro_awaitable |
| 497 | + async def taskfunc() -> Literal["test"]: |
| 498 | + return "test" |
| 499 | + |
| 500 | + with start_blocking_portal(anyio_backend_name, anyio_backend_options) as portal: |
| 501 | + future = portal.start_task_soon(taskfunc) |
| 502 | + assert future.result() == "test" |
| 503 | + |
486 | 504 | def test_start_task_soon_cancel_later( |
487 | 505 | self, anyio_backend_name: str, anyio_backend_options: dict[str, Any] |
488 | 506 | ) -> None: |
@@ -632,6 +650,18 @@ async def taskfunc(*, task_status: TaskStatus[str]) -> None: |
632 | 650 | assert value == "foo" |
633 | 651 | assert future.result() is None |
634 | 652 |
|
| 653 | + def test_start_non_corofunc( |
| 654 | + self, anyio_backend_name: str, anyio_backend_options: dict[str, Any] |
| 655 | + ) -> None: |
| 656 | + @return_non_coro_awaitable |
| 657 | + async def taskfunc(*, task_status: TaskStatus[str]) -> None: |
| 658 | + task_status.started("foo") |
| 659 | + |
| 660 | + with start_blocking_portal(anyio_backend_name, anyio_backend_options) as portal: |
| 661 | + future, value = portal.start_task(taskfunc) |
| 662 | + assert value == "foo" |
| 663 | + assert future.result() is None |
| 664 | + |
635 | 665 | def test_start_crash_before_started_call( |
636 | 666 | self, anyio_backend_name: str, anyio_backend_options: dict[str, Any] |
637 | 667 | ) -> None: |
|
0 commit comments