python-cq 0.11.1__tar.gz → 0.11.3__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.
Files changed (26) hide show
  1. {python_cq-0.11.1 → python_cq-0.11.3}/PKG-INFO +1 -1
  2. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/related_events.py +13 -9
  3. python_cq-0.11.3/cq/_core/scope.py +5 -0
  4. {python_cq-0.11.1 → python_cq-0.11.3}/pyproject.toml +1 -1
  5. python_cq-0.11.1/cq/_core/scope.py +0 -5
  6. {python_cq-0.11.1 → python_cq-0.11.3}/.gitignore +0 -0
  7. {python_cq-0.11.1 → python_cq-0.11.3}/LICENSE +0 -0
  8. {python_cq-0.11.1 → python_cq-0.11.3}/README.md +0 -0
  9. {python_cq-0.11.1 → python_cq-0.11.3}/cq/__init__.py +0 -0
  10. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/__init__.py +0 -0
  11. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/dispatcher/__init__.py +0 -0
  12. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/dispatcher/base.py +0 -0
  13. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/dispatcher/bus.py +0 -0
  14. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/dispatcher/lazy.py +0 -0
  15. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/dispatcher/pipe.py +0 -0
  16. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/handler.py +0 -0
  17. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/message.py +0 -0
  18. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/middleware.py +0 -0
  19. {python_cq-0.11.1 → python_cq-0.11.3}/cq/_core/pipetools.py +0 -0
  20. {python_cq-0.11.1 → python_cq-0.11.3}/cq/exceptions.py +0 -0
  21. {python_cq-0.11.1 → python_cq-0.11.3}/cq/ext/__init__.py +0 -0
  22. {python_cq-0.11.1 → python_cq-0.11.3}/cq/ext/fastapi.py +0 -0
  23. {python_cq-0.11.1 → python_cq-0.11.3}/cq/middlewares/__init__.py +0 -0
  24. {python_cq-0.11.1 → python_cq-0.11.3}/cq/middlewares/retry.py +0 -0
  25. {python_cq-0.11.1 → python_cq-0.11.3}/cq/middlewares/scope.py +0 -0
  26. {python_cq-0.11.1 → python_cq-0.11.3}/cq/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-cq
3
- Version: 0.11.1
3
+ Version: 0.11.3
4
4
  Summary: Lightweight CQRS library for async Python projects.
5
5
  Project-URL: Repository, https://github.com/100nm/python-cq
6
6
  Author: remimd
@@ -5,6 +5,7 @@ from typing import Protocol, runtime_checkable
5
5
 
6
6
  import anyio
7
7
  import injection
8
+ from anyio.abc import TaskGroup
8
9
 
9
10
  from cq._core.message import Event, EventBus
10
11
  from cq._core.scope import CQScope
@@ -20,20 +21,23 @@ class RelatedEvents(Protocol):
20
21
 
21
22
 
22
23
  @dataclass(repr=False, eq=False, frozen=True, slots=True)
23
- class SimpleRelatedEvents(RelatedEvents):
24
- items: list[Event] = field(default_factory=list)
24
+ class AnyIORelatedEvents(RelatedEvents):
25
+ event_bus: EventBus
26
+ task_group: TaskGroup
27
+ history: list[Event] = field(default_factory=list, init=False)
25
28
 
26
- def __bool__(self) -> bool:
27
- return bool(self.items)
29
+ def __bool__(self) -> bool: # pragma: no cover
30
+ return bool(self.history)
28
31
 
29
32
  def add(self, *events: Event) -> None:
30
- self.items.extend(events)
33
+ self.history.extend(events)
34
+ dispatch_method = self.event_bus.dispatch
35
+
36
+ for event in events:
37
+ self.task_group.start_soon(dispatch_method, event)
31
38
 
32
39
 
33
40
  @injection.scoped(CQScope.TRANSACTION, mode="fallback")
34
41
  async def related_events_recipe(event_bus: EventBus) -> AsyncIterator[RelatedEvents]:
35
- yield (instance := SimpleRelatedEvents())
36
-
37
42
  async with anyio.create_task_group() as task_group:
38
- for event in instance.items:
39
- task_group.start_soon(event_bus.dispatch, event)
43
+ yield AnyIORelatedEvents(event_bus, task_group)
@@ -0,0 +1,5 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class CQScope(StrEnum):
5
+ TRANSACTION = "__cq_transaction__"
@@ -23,7 +23,7 @@ test = [
23
23
 
24
24
  [project]
25
25
  name = "python-cq"
26
- version = "0.11.1"
26
+ version = "0.11.3"
27
27
  description = "Lightweight CQRS library for async Python projects."
28
28
  license = "MIT"
29
29
  license-files = ["LICENSE"]
@@ -1,5 +0,0 @@
1
- from enum import StrEnum, auto
2
-
3
-
4
- class CQScope(StrEnum):
5
- TRANSACTION = auto()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes