From 192af1e7bc8e07c8490a9747b820a016427df38e Mon Sep 17 00:00:00 2001 From: Sebastien Filion Date: Thu, 26 Aug 2021 11:06:58 -0400 Subject: [PATCH] docs: Add async iterator alternative for Deno.serveHttp (#11850) --- cli/dts/lib.deno.ns.d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 996aff3633..5e013466be 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; }