Skip to content

Commit d4af346

Browse files
committed
doc: infinite event example
1 parent be3729c commit d4af346

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See the [official Pub/Sub API repo](https://github.com/developerforce/pub-sub-ap
1212
- [Basic Example](#basic-example)
1313
- [Other Examples](#other-examples)
1414
- [Publish a platform event](#publish-a-platform-event)
15+
- [Subscribe to an infinite number of events](#subscribe-to-an-infinite-number-of-events)
1516
- [Subscribe with a replay ID](#subscribe-with-a-replay-id)
1617
- [Subscribe to past events in retention window](#subscribe-to-past-events-in-retention-window)
1718
- [Handle gRPC stream lifecycle events](#handle-grpc-stream-lifecycle-events)
@@ -264,6 +265,25 @@ const publishResult = await client.publish('/event/Sample__e', payload);
264265
console.log('Published event: ', JSON.stringify(publishResult));
265266
```
266267

268+
### Subscribe to an infinite number of events
269+
270+
You may subscribe to an infinite number of events by reconnecting the client automatically when the last requested event is received.
271+
272+
```js
273+
// Handle last requested event
274+
subscription.on('lastevent', async () => {
275+
try {
276+
// Re-subscribe to more events
277+
subscription = await client.subscribe(
278+
subscription.getTopicName(),
279+
NUMBER_OF_EVENTS
280+
);
281+
} catch (error) {
282+
console.log(error);
283+
}
284+
});
285+
```
286+
267287
### Subscribe with a replay ID
268288

269289
Subscribe to 5 account change events starting from a replay ID:

0 commit comments

Comments
 (0)