-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio as aio | ||
import gc | ||
import weakref | ||
from typing import Iterable, Tuple | ||
|
||
from aiuti.typing import AYields | ||
from aiuti.asyncio import AsyncBackgroundBatcher | ||
|
||
|
||
async def batch_things() -> weakref.ref[AsyncBackgroundBatcher[int, int]]: | ||
@AsyncBackgroundBatcher | ||
async def batcher( | ||
batch: Iterable[Tuple[str, int]], | ||
) -> AYields[Tuple[str, int]]: | ||
for key, value in batch: | ||
await aio.sleep(0) | ||
yield key, value + 1 | ||
|
||
await aio.gather(*map(batcher, range(30))) | ||
|
||
return weakref.ref(batcher) | ||
|
||
|
||
def test_gc() -> None: | ||
ref = aio.run(batch_things()) | ||
gc.collect() | ||
assert ref() is None |