diff options
author | Sebastien Filion <sebastienfilion@mac.com> | 2021-08-26 11:06:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 17:06:58 +0200 |
commit | 192af1e7bc8e07c8490a9747b820a016427df38e (patch) | |
tree | e4dadc5da6d532501c0803b51c562d9e1020eea8 | |
parent | 23a9bc099d21ef7d45fe0f76e2fc53740ca98f6a (diff) |
docs: Add async iterator alternative for Deno.serveHttp (#11850)
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 996aff363..5e013466b 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -2441,6 +2441,20 @@ declare namespace Deno { * * If `httpConn.nextRequest()` encounters an error or returns `null` * then the underlying HttpConn resource is closed automatically. + * + * Alternatively, you can also use the Async Iterator approach: + * + * ```ts + * async function handleHttp(conn: Deno.Conn) { + * for await (const e of Deno.serveHttp(conn)) { + * e.respondWith(new Response("Hello World")); + * } + * } + * + * for await (const conn of Deno.listen({ port: 80 })) { + * handleHttp(conn); + * } + * ``` */ export function serveHttp(conn: Conn): HttpConn; } |