pamoja.bus

Idiomatic event-bus facade.

One publisher, many subscribers, inside a single process. It is how the parts of a gateway talk to each other without knowing about each other, so a sampler can announce a reading and whatever cares about readings picks it up.

A subscriber only sees events published after it existed, so subscribe before publishing anything it needs to see.

 1"""Idiomatic event-bus facade.
 2
 3One publisher, many subscribers, inside a single process. It is how the parts of
 4a gateway talk to each other without knowing about each other, so a sampler can
 5announce a reading and whatever cares about readings picks it up.
 6
 7A subscriber only sees events published after it existed, so subscribe before
 8publishing anything it needs to see.
 9"""
10
11from __future__ import annotations
12
13from pamoja._native import EventBus
14
15__all__ = ["EventBus"]
class EventBus:

One endpoint on an event bus.

An endpoint both publishes and receives. Each subscriber needs its own, taken with subscribe, because an endpoint only sees events published after it existed.

def subscribe(self, /):

Takes another endpoint on the same bus.

The new endpoint sees events published from now on, not those already sent, so subscribe before publishing anything it needs to see.

def publish(self, /, event):

Publishes an event to every subscriber.

def next_event(self, /):

Waits for the next event on this endpoint, or None once the bus closes.