@@ -45,7 +45,7 @@ let mpx = new Multiplexer();
45
45
// as Buffer instances, use `.toString()` to decode their
46
46
// contents if necessary.
47
47
async funcion onMessage (channel , message ){
48
- console .log (" ch:" , channel .toString (), " msg:" , message .toString ());
48
+ console .log (" ch:" , channel .toString (), " msg:" , message .toString ());
49
49
}
50
50
51
51
// onDisconnect is a callback (can be async)
@@ -71,6 +71,10 @@ function onActivation(name){
71
71
let channelSub = mpx .createChannelSubcription (onMessage, null , null );
72
72
let patternSub = mpx .createPatternSubscription (" hello-*" , onMessage, null , onActivation);
73
73
let promiseSub = mpx .createPromiseSubscription (" hello-" );
74
+
75
+
76
+ // Close the multiplexer once you're done with it.
77
+ mpx .close ();
74
78
```
75
79
76
80
### ChannelSubscription
@@ -89,6 +93,9 @@ channelSub.add("chan3");
89
93
// Remove a channel
90
94
channelSub .remove (" chan2" );
91
95
96
+ // Clear the subscription (remove all channels)
97
+ channelSub .clear ();
98
+
92
99
// Close the subscription
93
100
channelSub .close ();
94
101
```
@@ -133,8 +140,10 @@ try {
133
140
//
134
141
// > PUBLISH hello-world "your-promise-payload"
135
142
//
136
- } catch redismpx .SubscriptionInactiveError as e {
137
- // Wait and then Retry? Return an error to the user? Up to you.
143
+ } catch (e) {
144
+ if (e instanceof redismpx .SubscriptionInactiveError ){
145
+ // Wait and then Retry? Return an error to the user? Up to you.
146
+ }
138
147
}
139
148
140
149
// A way of creating a promise that ensures no SubscriptionInactiveError
@@ -151,20 +160,23 @@ try {
151
160
let result = await promise
152
161
console .log (result .toString ()) // prints your-promise-payload
153
162
} catch (e) {
154
- if (e instanceof redismpx .PromiseTimeoutError ){
155
- // The promise timed out.
156
- } else if (e instanceof redismpx .SubscriptionInactiveError ) {
157
- // The subscription became inactive while the promise was
158
- // still pending.
159
- } else if (e instanceof redismpx .SubscriptionClosedError ) {
160
- // The subscription was closed while the promise was
161
- // still pending.
162
- }
163
+ if (e instanceof redismpx .PromiseTimeoutError ){
164
+ // The promise timed out.
165
+ } else if (e instanceof redismpx .SubscriptionInactiveError ) {
166
+ // The subscription became inactive while the promise was
167
+ // still pending.
168
+ } else if (e instanceof redismpx .SubscriptionClosedError ) {
169
+ // The subscription was closed while the promise was
170
+ // still pending.
171
+ }
163
172
}
164
173
165
- // Close the subscription (will automatically cancel all
166
- // outstanding promises and unlock all `waitFor*` waiters).
167
- promiseSub .close ()
174
+ // Clear the subscription (will reject all outstanding
175
+ // promises and unlock all `waitFor*` waiters)
176
+ promiseSub .clear ();
177
+
178
+ // Close the subscription (will call clear()).
179
+ promiseSub .close ();
168
180
```
169
181
170
182
## WebSocket Example
0 commit comments