Asyncio Event Hub
Asyncio Event Hub is a library that provides users with a way to easily create event-driven applications within the asyncio framework. It provides one main class asyncio_event_hub.controller.EventController, which can be used to emit events and add listeners (functions) to events that get called from the event loop in the same order they were added.
Installation
pip install asyncio-event-hub
Example
import asyncio_event_hub as aeh
import asyncio
# Create event controllers
main_controller = aeh.EventController()
sub_controller = aeh.EventController()
# Register sub_controller as a sub-controller of the main_controller
main_controller.add_subcontroller(sub_controller)
# Add listener via a decorator
@main_controller.listen("my_event")
async def listener1(a, b):
print(f"listener1({a}, {b})")
# Add listeners via a decorator
@main_controller.listen("my_event")
@sub_controller.listen("my_event")
def listener2(a, b):
print(f"listener2({a}, {b})")
async def stop(a):
main_controller.stop() # Stop main_controller and it's sub-controllers.
# Add listener through function
main_controller.add_listener("stop_event", stop, predicate=lambda a: a == 5) # Only call stop(a) if a is equal to 5
async def main():
main_controller.start() # Start main_controller and it's sub-controllers.
# Emit events into the event loop, executed asynchronously.
# listener1 is called once, listener2 is caller twice -
# once from main controller's event loop and once sub-controller's event loop. (not at this line, but asynchronously)
main_controller.emit("my_event", a=9, b =10)
# listener2 is called once from sub-controller's event loop. (not at this line, but asynchronously)
sub_controller.emit("my_event", a=1, b=2)
# await used to await for all listeners to finish processing event.
await main_controller.emit("stop_event", a=1) # Does not actually call anything since we have a predicate of a == 5.
await main_controller.emit("stop_event", a=5) # Stops controller asynchronously
asyncio.run(main())
Metadata
Release files for asyncio-event-hub 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| asyncio-event-hub-1.1.0.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asyncio_event_hub-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.4 kB
Release files / asyncio-event-hub-1.1.0.tar.gz
| Download URL | asyncio-event-hub-1.1.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85529543c0198f0e965fae2fbaa59d3bbc67ee2c175c54d87b5b67b661524274
|
|
BLAKE2b-256 checksum How to use checksums |
6c0aa0571e9113db475f596245003b96f9cd9c5e1a7f5ed9654488d2ccc737ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / asyncio_event_hub-1.1.0-py3-none-any.whl
| Download URL | asyncio_event_hub-1.1.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ea5fb9036be183eb995eb9f4d6fe8055dc3dc938ed8cd8babe512725c814d17
|
|
BLAKE2b-256 checksum How to use checksums |
1c4fe978277f6bc0ce241827c748f278309ebbcee743291b8a81d5cf51fb4cf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|