You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+104Lines changed: 104 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,3 +165,107 @@ for await (const event of client.readEvents('/books/42', {
165
165
```
166
166
167
167
*Note that `fromLatestEvent` and `lowerBound` can not be provided at the same time.*
168
+
169
+
#### Aborting Reading
170
+
171
+
If you need to abort reading use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
172
+
173
+
To abort reading independently of that, hand over an abort signal as third parameter when calling `readEvents`, and abort the appropriate `AbortController`:
// Somewhere else, abort the controller, which will cause
185
+
// reading to end.
186
+
controller.abort();
187
+
```
188
+
189
+
### Observing Events
190
+
191
+
To observe all events of a subject, call the `observeEvents` function with the subject as the first argument and an options object as the second argument. Set the `recursive` option to `false`. This ensures that only events of the given subject are returned, not events of nested subjects.
192
+
193
+
The function returns an asynchronous iterator, which you can use e.g. inside a `for await` loop:
This also allows you to observe *all* events ever written. To do so, provide `/` as the subject and set `recursive` to `true`, since all subjects are nested under the root subject.
216
+
217
+
#### Specifying Bounds
218
+
219
+
Sometimes you do not want to observe all events, but only a range of events. For that, you can specify the `lowerBound` option.
220
+
221
+
Specify the ID and whether to include or exclude it:
#### Starting From the Latest Event of a Given Type
233
+
234
+
To observe starting from the latest event of a given type, provide the `fromLatestEvent` option and specify the subject, the type, and how to proceed if no such event exists.
235
+
236
+
Possible options are `wait-for-event`, which waits for an event of the given type to happen, or `read-everything`, which effectively behaves as if `fromLatestEvent` was not specified:
*Note that `fromLatestEvent` and `lowerBound` can not be provided at the same time.*
252
+
253
+
#### Aborting Observing
254
+
255
+
If you need to abort observing use `break` or `return` within the `await for` loop. However, this only works if there is currently an iteration going on.
256
+
257
+
To abort observing independently of that, hand over an abort signal as third parameter when calling `observeEvents`, and abort the appropriate `AbortController`:
0 commit comments