examples
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| AppSignal anyenv.signals.examples Application-specific signal constrained to allowed event types. |
||
| AuditLogger anyenv.signals.examples Audit logger that listens to user events. |
||
| Counter anyenv.signals.examples Simple counter with signals for state changes. |
||
| FileEvent anyenv.signals.examples File operation event. |
||
| FileService anyenv.signals.examples Service handling file operations with type-safe events. |
||
| NotificationService anyenv.signals.examples Sends notifications based on various events. |
||
| User anyenv.signals.examples User domain object. |
||
| UserService anyenv.signals.examples Service handling user operations with type-safe events. |
||
| UserServiceV2 anyenv.signals.examples Alternative user service using factory pattern. |
🛈 DocStrings¶
Example usage of the signals package.
This module demonstrates core mechanisms of type-safe async signals.
AppSignal
¶
Bases: Signal[E]
Application-specific signal constrained to allowed event types.
Using a bounded TypeVar ensures that only User or FileEvent can be used as the signal's event type.
Source code in src/anyenv/signals/examples.py
AuditLogger
¶
Audit logger that listens to user events.
Source code in src/anyenv/signals/examples.py
Counter
¶
Simple counter with signals for state changes.
Source code in src/anyenv/signals/examples.py
increment
¶
FileEvent
dataclass
¶
FileService
¶
Service handling file operations with type-safe events.
Source code in src/anyenv/signals/examples.py
create_file
async
¶
Create file and emit creation event.
NotificationService
¶
Sends notifications based on various events.
Source code in src/anyenv/signals/examples.py
User
dataclass
¶
UserService
¶
Service handling user operations with type-safe events.
Source code in src/anyenv/signals/examples.py
UserServiceV2
¶
Alternative user service using factory pattern.
Source code in src/anyenv/signals/examples.py
create_app_signal
¶
create_app_signal(event_type: type[E]) -> Signal[*tuple[E],]
Create an application signal with auto-registration.
The bounded TypeVar ensures type safety.
demonstrate_basic_signals
async
¶
Demonstrate basic signal usage.
Source code in src/anyenv/signals/examples.py
demonstrate_factory_pattern
async
¶
Demonstrate factory pattern.
Source code in src/anyenv/signals/examples.py
demonstrate_type_constrained_signals
async
¶
Demonstrate type-constrained signals with cross-cutting concerns.