diff --git a/packages/docs/src/routes/docs/(qwikcity)/server$/index.mdx b/packages/docs/src/routes/docs/(qwikcity)/server$/index.mdx index 0e8aa7207e5..0a3ade9afb1 100644 --- a/packages/docs/src/routes/docs/(qwikcity)/server$/index.mdx +++ b/packages/docs/src/routes/docs/(qwikcity)/server$/index.mdx @@ -13,7 +13,8 @@ contributors: - wtlin1228 - adamdbradley - jemsco -updated_at: '2023-10-03T18:53:23Z' + - patrickjs +updated_at: '2024-05-11T17:00:00Z' created_at: '2023-03-29T02:35:29Z' --- @@ -23,7 +24,7 @@ created_at: '2023-03-29T02:35:29Z' `server$` is a form of RPC (Remote Procedure Call) mechanism between the client and server, just like a traditional HTTP endpoint but strongly typed thanks to Typescript, and easier to maintain. -Your new function will have the following signature: +Your new function will have the following signature: `([AbortSignal, ] ...): Promise` `AbortSignal` is optional, and allows you to cancel a long running request by terminating the connection. @@ -102,21 +103,32 @@ import { component$, useSignal } from '@builder.io/qwik'; import { server$ } from '@builder.io/qwik-city'; const stream = server$(async function* () { - for (let i = 0; i < 10; i++) { - yield i; + // Creation of an array with 10 undefined values + const iterationRange = Array(10).fill().entries(); + + for (const [index] of iterationRange) { + // Yield returns the index during each iteration + yield index; + + // Waiting for 1 second before the next iteration + // This simulates a delay in the execution await new Promise((resolve) => setTimeout(resolve, 1000)); } }); + export default component$(() => { const message = useSignal(''); return (