matrixlib.pubsub module

Implementation of the publish-subscribe pattern

class matrixlib.pubsub.Publisher

Publish messages that can be subscribed to.

Subscribers indicate which message types they are interested in by specifying the class of the messages.

async publish(message: Any) None

Publish a message to the subscribers

subscribe(message_type: type | Tuple[type, ...], subscriber: Callable[[Any], None | Awaitable[None]]) int

Subscribe to a message type

Returns an ID that can be used to unsubscribe

unsubscribe(id: int) bool

Unsubscribe from a message type

Returns whether or not the subscriber was found.