@palmetto/pubsub 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/subscriber.d.ts +11 -1
- package/dist/subscriber.js +16 -0
- package/package.json +1 -1
package/dist/subscriber.d.ts
CHANGED
|
@@ -20,7 +20,17 @@ export declare class Subscriber {
|
|
|
20
20
|
private readonly subscribedMessages;
|
|
21
21
|
constructor(logger: Logger, providers?: SubscriberProvider[]);
|
|
22
22
|
on<TU extends keyof SubscriberEvents>(event: TU, listener: SubscriberEvents[TU]): this;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Starts the subscriber for the given configuration. Depending on the protocol, the subscriber may not be started immediately.
|
|
25
|
+
*
|
|
26
|
+
* @param config The pubsub configuration to use for this subscriber
|
|
27
|
+
* @param onMessage The function to execute when a message arrives
|
|
28
|
+
* @returns An async function that will unsubscribe the subscriber when called
|
|
29
|
+
*/
|
|
30
|
+
subscribe<TMessage extends BaseMessage>(config: PubSubConfiguration, onMessage: (msg: TMessage, context: MessageContext) => Promise<MessageResult> | MessageResult): Promise<() => Promise<void>>;
|
|
31
|
+
/**
|
|
32
|
+
* Unsubscribes all active subscribers.
|
|
33
|
+
*/
|
|
24
34
|
unsubscribe(): Promise<void>;
|
|
25
35
|
addProvider(provider: SubscriberProvider): void;
|
|
26
36
|
removeProvider(providerOrTransport: SubscriberProvider | string): boolean;
|
package/dist/subscriber.js
CHANGED
|
@@ -32,6 +32,13 @@ class Subscriber {
|
|
|
32
32
|
this.events.on(event, listener);
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Starts the subscriber for the given configuration. Depending on the protocol, the subscriber may not be started immediately.
|
|
37
|
+
*
|
|
38
|
+
* @param config The pubsub configuration to use for this subscriber
|
|
39
|
+
* @param onMessage The function to execute when a message arrives
|
|
40
|
+
* @returns An async function that will unsubscribe the subscriber when called
|
|
41
|
+
*/
|
|
35
42
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
36
43
|
subscribe(config, onMessage) {
|
|
37
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -98,8 +105,17 @@ class Subscriber {
|
|
|
98
105
|
subscribedMessage = new SubscribedMessage(yield provider.startSubscribe(config, transform));
|
|
99
106
|
this.subscribedMessages.set(config, subscribedMessage);
|
|
100
107
|
this.logger.log(`Started subscriber for ${config.transport}:${config.name}`);
|
|
108
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
this.logger.log(`Stopping subscriber for ${config.transport}:${config.name}`);
|
|
110
|
+
this.subscribedMessages.delete(config);
|
|
111
|
+
yield subscribedMessage.stop();
|
|
112
|
+
this.logger.log(`Stopped subscriber for ${config.transport}:${config.name}`);
|
|
113
|
+
});
|
|
101
114
|
});
|
|
102
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Unsubscribes all active subscribers.
|
|
118
|
+
*/
|
|
103
119
|
unsubscribe() {
|
|
104
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
121
|
this.logger.log(`Stopping all ${this.subscribedMessages.size} subscribers`);
|