Skip to main content

Basic Event Handling System

Project description

ondosense-eventhandling

ondosense-eventhandling provides a basic implementation for event handling.

Example Usage

from ondosense.eventhandling import Event, EventDispatcher, EventSubscriber
from typing import List, Tuple

class SendGreetingsEvent(Event):
    name = 'greeting'
    _message: str = 'Hello World!'

    @property
    def message(self) -> str:
        return self._message

class GreetingSubscriber(EventSubscriber):

    def get_subscribed_events(self) -> dict[str, List[Tuple[str, int]]]:
        return {
            SendGreetingsEvent.name: [
                ('send_simple_greetings', 10),
                ('send_important_greetings', 20),
            ],
        }

    def send_simple_greetings(self, event: SendGreetingsEvent) -> None:
        print(event.message)

    def send_important_greetings(self, event: SendGreetingsEvent) -> None:
        important_message = f"!!! {event.message} !!!"
        important_message_length = len(important_message)
        print("!" * important_message_length)
        print(important_message)
        print("!" * important_message_length)

(
    EventDispatcher()
    .add_subscriber(GreetingSubscriber())
    .dispatch(SendGreetingsEvent())
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ondosense_eventhandling-0.1.2-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file ondosense_eventhandling-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ondosense_eventhandling-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14020dcc0eb75a7c9a56393bc5dd7d24283958ad43de2e948b1885e3672e8c55
MD5 4a15e8e22d167b0278fa2f49cb7ab02f
BLAKE2b-256 31d5852b04a6bf30944a56c01308dae714e975f78e1642736c17c51ebb121462

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page