Skip to content

Commit

Permalink
chore: apply automated updates
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Dec 4, 2024
1 parent 5831a5b commit adacfbe
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions docs/1.guide/6.websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ You can define WebSocket handlers in your existing [Event Handlers](/guide/event
<!-- automd:file code src="../../examples/websocket.ts" -->

```ts [websocket.ts]
import { createApp, defineWebSocketHandler } from "h3";
import { createH3, defineWebSocketHandler } from "h3";

export const app = createApp();
export const app = createH3();

app.use(() =>
fetch(
Expand Down Expand Up @@ -80,31 +80,25 @@ H3 has a built-in API to create server-sent events using `createEventStream(even
<!-- automd:file code src="../../examples/server-sent-events.ts" -->

```ts [server-sent-events.ts]
import { createApp, createRouter, eventHandler, createEventStream } from "h3";
import { createH3, createEventStream } from "h3";

export const app = createApp();
export const app = createH3();

const router = createRouter();
app.use(router);
app.get("/", (event) => {
const eventStream = createEventStream(event);

router.get(
"/",
eventHandler((event) => {
const eventStream = createEventStream(event);
// Send a message every second
const interval = setInterval(async () => {
await eventStream.push("Hello world");
}, 1000);

// Send a message every second
const interval = setInterval(async () => {
await eventStream.push("Hello world");
}, 1000);
// cleanup the interval when the connection is terminated or the writer is closed
eventStream.onClosed(() => {
clearInterval(interval);
});

// cleanup the interval when the connection is terminated or the writer is closed
eventStream.onClosed(() => {
clearInterval(interval);
});

return eventStream.send();
}),
);
return eventStream.send();
});
```

<!-- /automd -->

0 comments on commit adacfbe

Please sign in to comment.