From 498ec1c393f5bdb278ccf7b27a399350b9d69ef0 Mon Sep 17 00:00:00 2001 From: Razvan Date: Sun, 6 Oct 2024 10:46:34 +0200 Subject: [PATCH] chore(issue-58): adding a new example --- src/routes/issue-58/+page.svelte | 14 ++++++++++++++ src/routes/issue-58/events/+server.js | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/routes/issue-58/+page.svelte create mode 100644 src/routes/issue-58/events/+server.js diff --git a/src/routes/issue-58/+page.svelte b/src/routes/issue-58/+page.svelte new file mode 100644 index 0000000..13d0a40 --- /dev/null +++ b/src/routes/issue-58/+page.svelte @@ -0,0 +1,14 @@ + + + +

{$message}

diff --git a/src/routes/issue-58/events/+server.js b/src/routes/issue-58/events/+server.js new file mode 100644 index 0000000..4d151a8 --- /dev/null +++ b/src/routes/issue-58/events/+server.js @@ -0,0 +1,22 @@ +import { produce } from '$lib' +import { delay } from '$lib/delay.js' + +export async function GET() { + return produce( + async function start({ emit }) { + // eslint-disable-next-line no-constant-condition + while (true) { + const { error } = emit('message', `${Date.now()}`) + if (error) { + return + } + await delay(1000) + } + }, + { + stop() { + console.log('Client disconnected!!') + }, + }, + ) +}