caffeinism-utils 0.0.169__tar.gz → 0.0.170__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.169
3
+ Version: 0.0.170
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.169"
3
+ version = "0.0.170"
4
4
  description = ""
5
5
  authors = ["Kim Minjong <make.dirty.code@gmail.com>"]
6
6
  readme = "README.md"
@@ -26,6 +26,8 @@ async def rate_limit_iterator(aiterator, iters_per_second):
26
26
 
27
27
  T = TypeVar("T")
28
28
 
29
+ __CLOSE = object()
30
+
29
31
 
30
32
  class StreamQueue(Generic[T]):
31
33
  def __init__(self):
@@ -35,6 +37,9 @@ class StreamQueue(Generic[T]):
35
37
  return self.queue.put(data)
36
38
 
37
39
  async def __aiter__(self) -> AsyncGenerator[T]:
38
- while (iterator := await self.queue.get()) is not None:
40
+ while (iterator := await self.queue.get()) is not __CLOSE:
39
41
  async for it in iterator:
40
42
  yield it
43
+
44
+ async def close(self):
45
+ await self.queue.put(__CLOSE)
@@ -103,7 +103,7 @@ async def _aprefetch_aiterator(
103
103
  while True:
104
104
  if prefetched is not None:
105
105
  try:
106
- ret = await prefetched
106
+ ret = await asyncio.shield(prefetched)
107
107
  except StopAsyncIteration:
108
108
  break
109
109