haiway 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
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.
- haiway/context/disposables.py +45 -35
- haiway/utils/queue.py +0 -4
- {haiway-0.4.0.dist-info → haiway-0.5.0.dist-info}/METADATA +1 -1
- {haiway-0.4.0.dist-info → haiway-0.5.0.dist-info}/RECORD +7 -7
- {haiway-0.4.0.dist-info → haiway-0.5.0.dist-info}/LICENSE +0 -0
- {haiway-0.4.0.dist-info → haiway-0.5.0.dist-info}/WHEEL +0 -0
- {haiway-0.4.0.dist-info → haiway-0.5.0.dist-info}/top_level.txt +0 -0
haiway/context/disposables.py
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
from asyncio import gather
|
1
|
+
from asyncio import gather
|
2
2
|
from collections.abc import Iterable
|
3
|
+
from contextlib import AbstractAsyncContextManager
|
4
|
+
from itertools import chain
|
3
5
|
from types import TracebackType
|
4
|
-
from typing import
|
6
|
+
from typing import final
|
5
7
|
|
6
8
|
from haiway.state import State
|
9
|
+
from haiway.utils import freeze
|
7
10
|
|
8
11
|
__all__ = [
|
9
12
|
"Disposable",
|
10
13
|
"Disposables",
|
11
14
|
]
|
12
15
|
|
13
|
-
|
14
|
-
@runtime_checkable
|
15
|
-
class Disposable(Protocol):
|
16
|
-
async def initialize(self) -> State | None: ...
|
17
|
-
async def dispose(self) -> None: ...
|
16
|
+
type Disposable = AbstractAsyncContextManager[Iterable[State] | State | None]
|
18
17
|
|
19
18
|
|
20
19
|
@final
|
@@ -25,39 +24,35 @@ class Disposables:
|
|
25
24
|
) -> None:
|
26
25
|
self._disposables: tuple[Disposable, ...] = disposables
|
27
26
|
|
28
|
-
|
29
|
-
return [
|
30
|
-
state
|
31
|
-
for state in await gather(
|
32
|
-
*[disposable.initialize() for disposable in self._disposables],
|
33
|
-
)
|
34
|
-
if state is not None
|
35
|
-
]
|
36
|
-
|
37
|
-
async def dispose(self) -> None:
|
38
|
-
results: list[BaseException | None] = await shield(
|
39
|
-
gather(
|
40
|
-
*[disposable.dispose() for disposable in self._disposables],
|
41
|
-
return_exceptions=True,
|
42
|
-
),
|
43
|
-
)
|
27
|
+
freeze(self)
|
44
28
|
|
45
|
-
|
46
|
-
|
47
|
-
exception for exception in results if exception is not None
|
48
|
-
]
|
29
|
+
def __bool__(self) -> bool:
|
30
|
+
return len(self._disposables) > 0
|
49
31
|
|
50
|
-
|
51
|
-
|
32
|
+
async def _initialize(
|
33
|
+
self,
|
34
|
+
disposable: Disposable,
|
35
|
+
/,
|
36
|
+
) -> Iterable[State]:
|
37
|
+
match await disposable.__aenter__():
|
38
|
+
case None:
|
39
|
+
return ()
|
52
40
|
|
53
|
-
|
54
|
-
|
41
|
+
case State() as single:
|
42
|
+
return (single,)
|
55
43
|
|
56
|
-
|
57
|
-
|
44
|
+
case multiple:
|
45
|
+
return multiple
|
58
46
|
|
59
47
|
async def __aenter__(self) -> Iterable[State]:
|
60
|
-
return
|
48
|
+
return [
|
49
|
+
*chain.from_iterable(
|
50
|
+
state
|
51
|
+
for state in await gather(
|
52
|
+
*[self._initialize(disposable) for disposable in self._disposables],
|
53
|
+
)
|
54
|
+
)
|
55
|
+
]
|
61
56
|
|
62
57
|
async def __aexit__(
|
63
58
|
self,
|
@@ -65,4 +60,19 @@ class Disposables:
|
|
65
60
|
exc_val: BaseException | None,
|
66
61
|
exc_tb: TracebackType | None,
|
67
62
|
) -> None:
|
68
|
-
await
|
63
|
+
results: list[bool | BaseException | None] = await gather(
|
64
|
+
*[
|
65
|
+
disposable.__aexit__(
|
66
|
+
exc_type,
|
67
|
+
exc_val,
|
68
|
+
exc_tb,
|
69
|
+
)
|
70
|
+
for disposable in self._disposables
|
71
|
+
],
|
72
|
+
return_exceptions=True,
|
73
|
+
)
|
74
|
+
|
75
|
+
exceptions: list[BaseException] = [exc for exc in results if isinstance(exc, BaseException)]
|
76
|
+
|
77
|
+
if len(exceptions) > 1:
|
78
|
+
raise BaseExceptionGroup("Disposing errors", exceptions)
|
haiway/utils/queue.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
from asyncio import AbstractEventLoop, CancelledError, Future, get_running_loop
|
2
2
|
from collections import deque
|
3
3
|
from collections.abc import AsyncIterator
|
4
|
-
from typing import Self
|
5
4
|
|
6
5
|
__all__ = [
|
7
6
|
"AsyncQueue",
|
@@ -63,9 +62,6 @@ class AsyncQueue[Element](AsyncIterator[Element]):
|
|
63
62
|
def cancel(self) -> None:
|
64
63
|
self.finish(exception=CancelledError())
|
65
64
|
|
66
|
-
def __aiter__(self) -> Self:
|
67
|
-
return self
|
68
|
-
|
69
65
|
async def __anext__(self) -> Element:
|
70
66
|
assert self._waiting is None, "Only a single queue consumer is supported!" # nosec: B101
|
71
67
|
|
@@ -2,7 +2,7 @@ haiway/__init__.py,sha256=hLc3-FDmNQEV4r-RLOiGjWtYSk7krU8vRMBaZyRU08g,1267
|
|
2
2
|
haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
haiway/context/__init__.py,sha256=21Y3zvRo1bHASZD6B_FNkU28k1-g88RdmUyqxvYXJxg,336
|
4
4
|
haiway/context/access.py,sha256=zPQcQBp5XMlNuszbxhtzi-5mNpDLpZ6PT-gVFDBH0dA,14115
|
5
|
-
haiway/context/disposables.py,sha256=
|
5
|
+
haiway/context/disposables.py,sha256=DZjnMp-wMfF-em2Wjhbm1MvXubNpuzFBT70BQNIxC7M,2019
|
6
6
|
haiway/context/metrics.py,sha256=R6BIH3Pwtm_fQqPZmTei3nUGNDAZEnvUKaVxwjWxgS0,10755
|
7
7
|
haiway/context/state.py,sha256=GxGwPQTK8FdSprBd83lQbA9veubp0o93_1Yk3gb7HMc,3000
|
8
8
|
haiway/context/tasks.py,sha256=xXtXIUwXOra0EePTdkcEbMOmpWwFcO3hCRfR_IfvAHk,1978
|
@@ -28,9 +28,9 @@ haiway/utils/immutable.py,sha256=K34ZIMzbkpgkHKH-KF73plEbXExsajNRkRTYp9nJEf4,620
|
|
28
28
|
haiway/utils/logs.py,sha256=oDsc1ZdqKDjlTlctLbDcp9iX98Acr-1tdw-Pyg3DElo,1577
|
29
29
|
haiway/utils/mimic.py,sha256=BkVjTVP2TxxC8GChPGyDV6UXVwJmiRiSWeOYZNZFHxs,1828
|
30
30
|
haiway/utils/noop.py,sha256=qgbZlOKWY6_23Zs43OLukK2HagIQKRyR04zrFVm5rWI,344
|
31
|
-
haiway/utils/queue.py,sha256=
|
32
|
-
haiway-0.
|
33
|
-
haiway-0.
|
34
|
-
haiway-0.
|
35
|
-
haiway-0.
|
36
|
-
haiway-0.
|
31
|
+
haiway/utils/queue.py,sha256=oQ3GXCJ-PGNtMEr6EPdgqAvYZoj8lAa7Z2drBKBEoBM,2345
|
32
|
+
haiway-0.5.0.dist-info/LICENSE,sha256=GehQEW_I1pkmxkkj3NEa7rCTQKYBn7vTPabpDYJlRuo,1063
|
33
|
+
haiway-0.5.0.dist-info/METADATA,sha256=vKid6rHV96N2FZJZ7WUmSBgpqzG5xeMkGsxY43OVNHY,3872
|
34
|
+
haiway-0.5.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
35
|
+
haiway-0.5.0.dist-info/top_level.txt,sha256=_LdXVLzUzgkvAGQnQJj5kQfoFhpPW6EF4Kj9NapniLg,7
|
36
|
+
haiway-0.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|