Skip to content

Commit

Permalink
docs: add base path to link urls
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWid committed Oct 27, 2024
1 parent f9d1dab commit a6d34e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions docs/src/content/docs/guides/batching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ sidebar:

import {Tabs, TabItem, Code, Aside, Steps, LinkCard} from "@astrojs/starlight/components";

While SSE is already performant and bandwidth-efficient, sending many events at a time by repeatedly calling [`Session#push`](/reference/api#sessionpush-data-unknown-eventname-string-eventid-string--this) can be wasteful as every call will initiate a full TCP round trip where the client must send acknowledgement packets back for every event it receives.
While SSE is already performant and bandwidth-efficient, sending many events at a time by repeatedly calling [`Session#push`](/better-sse/reference/api#sessionpush-data-unknown-eventname-string-eventid-string--this) can be wasteful as every call will initiate a full TCP round trip where the client must send acknowledgement packets back for every event it receives.

*Event buffers* improve this process by allowing you to batch and send multiple events in a single network transmission, greatly improving performance and lowering overall bandwidth usage.

## Using the `batch` method

To batch and send multiple events at a time, simply invoke [`Session#batch`](/reference/api#sessionbatch-batcher-eventbuffer--buffer-eventbuffer--void--promisevoid--promisevoid) method and pass a callback that takes an [event buffer](/reference/api#eventbuffer) as its first argument:
To batch and send multiple events at a time, simply invoke [`Session#batch`](/better-sse/reference/api#sessionbatch-batcher-eventbuffer--buffer-eventbuffer--void--promisevoid--promisevoid) method and pass a callback that takes an [event buffer](/better-sse/reference/api#eventbuffer) as its first argument:

```typescript title="server.ts"
await session.batch(async (buffer) => {
await buffer.push("Hello world!");
});
```

You can use the same helper methods as you would with the session itself ([`push`](/reference/api#sessionpush-data-unknown-eventname-string-eventid-string--this), [`stream`](/reference/api#sessionstream-stream-readable-options-object--promiseboolean) and [`iterate`](/reference/api#sessioniterate-iterable-iterable--asynciterable-options-object--promisevoid)) with the buffer.
You can use the same helper methods as you would with the session itself ([`push`](/better-sse/reference/api#sessionpush-data-unknown-eventname-string-eventid-string--this), [`stream`](/better-sse/reference/api#sessionstream-stream-readable-options-object--promiseboolean) and [`iterate`](/better-sse/reference/api#sessioniterate-iterable-iterable--asynciterable-options-object--promisevoid)) with the buffer.

When the callback finishes execution - or resolves if it returns a promise - every event created with the buffer will be sent to the client all at once in a single network transmission.

Expand All @@ -44,7 +44,7 @@ buffer.iterate(["My", "huge", "event", "list"]);
session.batch(buffer);
```

Or send the buffer contents to every session on a [channel](/guides/channels), for example:
Or send the buffer contents to every session on a [channel](/better-sse/guides/channels), for example:

```typescript title="server.ts"
channel.activeSessions.forEach((session) => {
Expand All @@ -55,7 +55,7 @@ channel.activeSessions.forEach((session) => {
<Aside title="Sanitize your data" type="caution" >
Keep in mind that, unless you explicitly pass them via [the `sanitizer` and/or `serializer` constructor arguments](#new-eventbufferoptions-), event buffers do *not* have the same data serializer and sanitizer functions as the session being called.

This does not apply when you use the [`Session#batch`](/reference/api(sessionbatch-batcher-eventbuffer--buffer-eventbuffer--void--promisevoid--promisevoid)) method as it will automatically copy the serializer and sanitizer from the session to the event buffer instance it creates for you.
This does not apply when you use the [`Session#batch`](/better-sse/reference/api(sessionbatch-batcher-eventbuffer--buffer-eventbuffer--void--promisevoid--promisevoid)) method as it will automatically copy the serializer and sanitizer from the session to the event buffer instance it creates for you.
</Aside>

### Send individual event fields
Expand All @@ -81,4 +81,4 @@ res.write(buffer.read());
buffer.clear();
```

This is an advanced use-case. For most users, you should still stick with using [`Session`](/reference/api#sessionstate) by default.
This is an advanced use-case. For most users, you should still stick with using [`Session`](/better-sse/reference/api#sessionstate) by default.
4 changes: 2 additions & 2 deletions docs/src/content/docs/guides/channels.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ sidebar:
import {Tabs, TabItem, Code, Aside, Steps, LinkCard} from "@astrojs/starlight/components";

<Aside>
You should read the [Getting Started](/guides/getting-started) guide first if you haven't already.
You should read the [Getting Started](/better-sse/guides/getting-started) guide first if you haven't already.
</Aside>

*Channels* are an abstraction that make it easy to broadcast events to many clients at once.

When a client first connects, you register its session to one or many channels and from then-on any events broadcast on those channels will also be sent to that client.

Don't worry about *de*registering the session from the channel; that is automatically handled for you when the session disconnects, [but you can also do it manually](/reference/api/#channelderegister-session-session--this) if you no longer wish to listen for events on a channel at any time.
Don't worry about *de*registering the session from the channel; that is automatically handled for you when the session disconnects, [but you can also do it manually](/better-sse/reference/api/#channelderegister-session-session--this) if you no longer wish to listen for events on a channel at any time.

Channels can be used for things such as notification systems, chat rooms and synchronizing data between multiple clients.

Expand Down
12 changes: 6 additions & 6 deletions docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ hero:
tagline: Dead-simple real-time server-to-client communication without WebSockets.
actions:
- text: Get started
link: /guides/getting-started
link: /better-sse/guides/getting-started
icon: right-arrow
- text: API reference
link: /reference/api
link: /better-sse/reference/api
icon: document
variant: minimal
---
Expand Down Expand Up @@ -56,8 +56,8 @@ import clientCode from "/src/content/snippets/home-client.ts?raw";
## Get started

<CardGrid>
<LinkCard title="Getting started guide" description="Learn about using SSE to send events to your clients in real time" href="/guides/getting-started" />
<LinkCard title="API reference" description="Read the reference documentation for all package exports" href="/reference/api" />
<LinkCard title="Compare with other tools" description="Compare the features of Better SSE with other Node SSE libraries" href="/reference/comparison" />
<LinkCard title="Usage recipes" description="See examples of using Better SSE with popular HTTP frameworks" href="/reference/recipes" />
<LinkCard title="Getting started guide" description="Learn about using SSE to send events to your clients in real time" href="/better-sse/guides/getting-started" />
<LinkCard title="API reference" description="Read the reference documentation for all package exports" href="/better-sse/reference/api" />
<LinkCard title="Compare with other tools" description="Compare the features of Better SSE with other Node SSE libraries" href="/better-sse/reference/comparison" />
<LinkCard title="Usage recipes" description="See examples of using Better SSE with popular HTTP frameworks" href="/better-sse/reference/recipes" />
</CardGrid>

0 comments on commit a6d34e7

Please sign in to comment.