Provides an abstract implementation for a participant that can receive from and publish to, topical notifications of a mediator.
▶Example 1
Example 1
import { TAbstractParticipant } from './t_abstract_participant.ts'; import type { ParticipantTopicMessage } from './types/mod.ts'; type MyTopics = { TopicA: string; TopicB: { value: number }; TopicC: { timestamp: Date }; }; class MyParticipant extends TAbstractParticipant<MyTopics> { next(value: ParticipantTopicMessage<MyTopics>): void { const [topic, message] = value; if (topic === 'TopicA') { console.log(message); } else if (topic === 'TopicB') { console.log(`Took ${(message as MyTopics["TopicB"]).value} seconds to complete.`); } else { console.log(`Completed at ${(message as MyTopics["TopicC"]).timestamp}.`); } } error(error: Error): void { console.error(error); } } const participant = new MyParticipant(['TopicA', 'TopicB']);
new
TAbstractParticipant(topics?: K[])
Initializes a new instance of the TAbstractSubscriber class with the topics the instance will subscribe to.
readonly
participantId: symbol
The unique identifier for this participant.
protected
mediators: TBaseMediator<PubSubTopics<T>>[]
The mediators this participant is subscribed to.
publish(message: ParticipantTopicMessage<T>): void
Publishes a message to the mediator.
subscribe(mediator: TBaseMediator<PubSubTopics<T>>): IDisposable
Subscribes the participant to a mediator.