Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: Better document cursor reuse #301

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ See the [Fauna Documentation](https://docs.fauna.com/fauna/current/) for additio
- [Client timeout](#client-timeout)
- [HTTP/2 session idle timeout](#http2-session-idle-timeout)
- [Event Feeds](#event-feeds)
- [Request an Event Feed](#request-a-event-feed)
- [Iterate on an Event Feed](#iterate-on-a-event-feed)
- [Request an Event Feed](#request-an-event-feed)
- [Iterate on an Event Feed](#iterate-on-an-event-feed)
- [Error handling](#error-handling)
- [Event Feed options](#event-feed-options)
- [Event Streaming](#event-streaming)
Expand Down Expand Up @@ -478,7 +478,7 @@ The driver supports [Event Feeds](https://docs.fauna.com/fauna/current/learn/cdc

An Event Feed asynchronously polls an [event source](https://docs.fauna.com/fauna/current/learn/cdc/#create-an-event-source) for events.

To get an event source, append `eventSource()` or `eventsOn()` to a set from a
To get an event source, append `eventSource()` or `eventsOn()` to a
[supported Set](https://docs.fauna.com/fauna/current/reference/streaming_reference/#sets).

To get paginated events, pass the event source to `feed()`:
Expand All @@ -497,6 +497,9 @@ const { initialPage, eventSource } = response.data;
const feed = client.feed(eventSource);
```

If changes occur between the creation of the event source and the `feed()`
request, the feed replays and emits any related events.

You can also pass a query that produces an event source directly to `feed()`:

```javascript
Expand All @@ -505,7 +508,10 @@ const query = fql`Product.all().eventsOn(.price, .stock)`;
const feed = client.feed(query);
```

### Iterate on a Event Feed
If you pass an event source query to `feed()`, the driver creates the event
source and requests the event feed at the same time.

### Iterate on an Event Feed

`feed()` returns a `FeedClient` instance that can act as an `AsyncIterator`. You can use `for await...of` to iterate through all the pages:

Expand Down Expand Up @@ -592,6 +598,10 @@ const options: FeedClientConfiguration = {
client.feed(fql`Product.all().eventSource()`, options);
```

You can reuse
jrodewig marked this conversation as resolved.
Show resolved Hide resolved
[cursors](https://docs.fauna.com/fauna/current/reference/cdc/#get-events-after-a-specific-cursor)
across event sources with identical queries in the same database.

## Event Streaming

The driver supports [Event Streaming](https://docs.fauna.com/fauna/current/learn/streaming).
Expand Down
Loading