caffeinism-utils 0.0.171__tar.gz → 0.0.172__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: caffeinism-utils
3
- Version: 0.0.171
3
+ Version: 0.0.172
4
4
  Summary:
5
5
  Author: Kim Minjong
6
6
  Author-email: make.dirty.code@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "caffeinism-utils"
3
- version = "0.0.171"
3
+ version = "0.0.172"
4
4
  description = ""
5
5
  authors = ["Kim Minjong <make.dirty.code@gmail.com>"]
6
6
  readme = "README.md"
@@ -26,35 +26,35 @@ async def rate_limit_iterator(aiterator, iters_per_second):
26
26
 
27
27
  T = TypeVar("T")
28
28
 
29
- __CLOSE = object()
30
29
 
30
+ class BaseStreamQueue(Generic[T]):
31
+ _CLOSE = object()
31
32
 
32
- class StreamQueue(Generic[T]):
33
33
  def __init__(self):
34
- self.queue = asyncio.Queue[T]()
34
+ self.queue = asyncio.Queue()
35
+
36
+ async def close(self):
37
+ await self.queue.put(self._CLOSE)
38
+
39
+
40
+ class StreamQueue(BaseStreamQueue):
41
+ queue: asyncio.Queue[T]
35
42
 
36
43
  def put(self, data: T) -> None:
37
44
  return self.queue.put(data)
38
45
 
39
46
  async def __aiter__(self) -> AsyncGenerator[T]:
40
- while (it := await self.queue.get()) is not __CLOSE:
47
+ while (it := await self.queue.get()) is not self._CLOSE:
41
48
  yield it
42
49
 
43
- async def close(self):
44
- await self.queue.put(__CLOSE)
45
50
 
46
-
47
- class StreamIteratorQueue(Generic[T]):
48
- def __init__(self):
49
- self.queue = asyncio.Queue[AsyncIterable[T]]()
51
+ class StreamIteratorQueue(BaseStreamQueue):
52
+ queue: asyncio.Queue[AsyncIterable[T]]
50
53
 
51
54
  def put(self, data: AsyncIterable[T]) -> None:
52
55
  return self.queue.put(data)
53
56
 
54
57
  async def __aiter__(self) -> AsyncGenerator[T]:
55
- while (iterator := await self.queue.get()) is not __CLOSE:
58
+ while (iterator := await self.queue.get()) is not self._CLOSE:
56
59
  async for it in iterator:
57
60
  yield it
58
-
59
- async def close(self):
60
- await self.queue.put(__CLOSE)