haiway 0.20.0__py3-none-any.whl → 0.20.1__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.
@@ -8,7 +8,7 @@ from haiway.context import ctx
8
8
  __all__ = ("process_concurrently",)
9
9
 
10
10
 
11
- async def process_concurrently[Element]( # noqa: C901
11
+ async def process_concurrently[Element]( # noqa: C901, PLR0912
12
12
  source: AsyncIterator[Element],
13
13
  /,
14
14
  handler: Callable[[Element], Coroutine[Any, Any, None]],
@@ -37,12 +37,16 @@ async def process_concurrently[Element]( # noqa: C901
37
37
  assert concurrent_tasks > 0 # nosec: B101
38
38
  running: set[Task[None]] = set()
39
39
  try:
40
- while element := await anext(source, None):
40
+ while True:
41
+ element: Element = await anext(source)
42
+ running.add(ctx.spawn(handler, element))
41
43
  if len(running) < concurrent_tasks:
42
- running.add(ctx.spawn(handler, element))
43
44
  continue # keep spawning tasks
44
45
 
45
- completed, running = await wait(running, return_when=FIRST_COMPLETED)
46
+ completed, running = await wait(
47
+ running,
48
+ return_when=FIRST_COMPLETED,
49
+ )
46
50
 
47
51
  for task in completed:
48
52
  if exc := task.exception():
@@ -61,14 +65,21 @@ async def process_concurrently[Element]( # noqa: C901
61
65
 
62
66
  raise exc
63
67
 
68
+ except StopAsyncIteration:
69
+ pass # just stop and proceed to finally
70
+
64
71
  finally:
65
- completed, _ = await wait(running, return_when=ALL_COMPLETED)
66
- for task in completed:
67
- if exc := task.exception():
68
- if not ignore_exceptions:
69
- raise exc
70
-
71
- ctx.log_error(
72
- f"Concurrent processing error - {type(exc)}: {exc}",
73
- exception=exc,
74
- )
72
+ if running:
73
+ completed, _ = await wait(
74
+ running,
75
+ return_when=ALL_COMPLETED,
76
+ )
77
+ for task in completed:
78
+ if exc := task.exception():
79
+ if not ignore_exceptions:
80
+ raise exc
81
+
82
+ ctx.log_error(
83
+ f"Concurrent processing error - {type(exc)}: {exc}",
84
+ exception=exc,
85
+ )
haiway/state/structure.py CHANGED
@@ -551,6 +551,14 @@ class State(metaclass=StateMeta):
551
551
  case _:
552
552
  raise TypeError(f"Expected '{cls.__name__}', received '{type(value).__name__}'")
553
553
 
554
+ @classmethod
555
+ def from_mapping(
556
+ cls,
557
+ value: Mapping[str, Any],
558
+ /,
559
+ ) -> Self:
560
+ return cls(**value)
561
+
554
562
  def __init__(
555
563
  self,
556
564
  **kwargs: Any,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.20.0
3
+ Version: 0.20.1
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Project-URL: Homepage, https://miquido.com
6
6
  Project-URL: Repository, https://github.com/miquido/haiway.git
@@ -11,7 +11,7 @@ haiway/context/types.py,sha256=VDWXJySihfvSSPzY09PaGk6j5S9HgmAUboBGCZ8o_4k,766
11
11
  haiway/helpers/__init__.py,sha256=_A-JYAPemd-2o4NxxchaZENu8gANL8QDxK5ADzInXUU,670
12
12
  haiway/helpers/asynchrony.py,sha256=2NtuMklKHyU2o7H_Y_wyN6mxa13wdgI6yETjPbgSHPA,8136
13
13
  haiway/helpers/caching.py,sha256=BqgcUGQSAmXsuLi5V8EwlZzuGyutHOn1V4k7BHsGKeg,14347
14
- haiway/helpers/concurrent.py,sha256=04pWpS7qOQDD1pa2ifhFwedPcl4sRinhe-KgyDe5GF0,2296
14
+ haiway/helpers/concurrent.py,sha256=xGMcan_tiETAHQs1YFmgYpA4YMFo6rIbFKvNeMlRFG8,2551
15
15
  haiway/helpers/observability.py,sha256=3G0eRE1WYTGRujS0mxzYbLR4MlKnoYllE8cu2Eb_23w,11073
16
16
  haiway/helpers/retries.py,sha256=52LA85HejTiSmCmTMAA9c8oUqD_VnhbTn1b3kwlU52c,9032
17
17
  haiway/helpers/throttling.py,sha256=hwhruBXepve2TJA4vsaO4WwTFkclt5eNiZ8U0mo-mlI,5015
@@ -23,7 +23,7 @@ haiway/state/__init__.py,sha256=AaMqlMhO4zKS_XNevy3A7BHh5PxmguA-Sk_FnaNDY1Q,355
23
23
  haiway/state/attributes.py,sha256=sububiFP23aBB8RGk6OvTUp7BEY6S0kER_uHC09yins,26733
24
24
  haiway/state/path.py,sha256=bv5MI3HmUyku78k0Sz5lc7Q_Bay53iom1l3AL5KZs-4,32143
25
25
  haiway/state/requirement.py,sha256=_tA6CPyFX6WTjJ0Yk2jeMs-At17ex8Yl8y1-s24idas,12793
26
- haiway/state/structure.py,sha256=wZqTcX3BaKbjMSKjAukPHfR9A_nQibLW9i_BWpWUVYs,23118
26
+ haiway/state/structure.py,sha256=KKIId-mrHAzGjYKKlvnlscMijVZVM8nDLnAwCFn1sTc,23259
27
27
  haiway/state/validation.py,sha256=eDOZKRrfd-dmdbqoHcLacdCVKmVCEpwt239EG6ljNF8,23557
28
28
  haiway/types/__init__.py,sha256=73DMgf60Ftf1gLRCSQG66Nyu3_QFjdRJggBtS4-RQkY,342
29
29
  haiway/types/default.py,sha256=59chcOaoGqI2to08RamCCLluimfYbJp5xbYl3fWaLrM,4153
@@ -40,7 +40,7 @@ haiway/utils/mimic.py,sha256=L5AS4WEL2aPMZAQZlvLvRzHl0cipI7ivky60_eL4iwY,1822
40
40
  haiway/utils/noop.py,sha256=U8ocfoCgt-pY0owJDPtrRrj53cabeIXH9qCKWMQnoRk,1336
41
41
  haiway/utils/queue.py,sha256=6v2u3pA6A44IuCCTOjmCt3yLyOcm7PCRnrIGo25j-1o,6402
42
42
  haiway/utils/stream.py,sha256=lXaeveTY0-AYG5xVzcQYaiC6SUD5fUtHoMXiQcrQAAM,5723
43
- haiway-0.20.0.dist-info/METADATA,sha256=QbQTKdDVsoT878zfWl1NwrbEPo8z5dPvC1EO29OiBMk,4527
44
- haiway-0.20.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
45
- haiway-0.20.0.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
46
- haiway-0.20.0.dist-info/RECORD,,
43
+ haiway-0.20.1.dist-info/METADATA,sha256=BJSukCFzSCZuPbK0HmUsBGdhhbC-K3yfH9ocia9rYJA,4527
44
+ haiway-0.20.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
45
+ haiway-0.20.1.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
46
+ haiway-0.20.1.dist-info/RECORD,,