Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

PubSub.Broker

import { PubSub } from "https://raw.githubusercontent.com/i-xi-dev/pubsub.es/2.0.17/mod.ts"; 

const { Broker } = PubSub;

The message broker.

class Broker<T> {
constructor();
clear(): void;
async publish(topic: Topic, message: T): Promise<void>;
subscribe(
topic: Topic,
callback: (message: T) => Promise<void>,
): void;
unsubscribe(topic: Topic, callback: (message: T) => Promise<void>): void;
}

§Type Parameters

§Constructors

§
new Broker()
[src]

§Methods

§
clear(): void
[src]

Clears all subscriptions and all topics.

§
publish(topic: Topic, message: T): Promise<void>
[src]

Sends a message to the topic.

@param topic
  • The topic.
@param message
  • A message to send.
§
subscribe(topic: Topic, callback: (message: T) => Promise<void>, options?: SubscriptionOptions): void
[src]

Subscribes to a topic to consume messages.

@param topic
  • The topic to subscribe.
@param callback
  • The subscription callback.
@param options
  • The PubSub.SubscriptionOptions object.
§
unsubscribe(topic: Topic, callback: (message: T) => Promise<void>): void
[src]

Unsubscribe from the topic.

@param topic
  • The topic to be unsubscribed.
@param callback
  • The subscription callback.