mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
docs: Add async iterator alternative for Deno.serveHttp (#11850)
This commit is contained in:
parent
23a9bc099d
commit
192af1e7bc
1 changed files with 14 additions and 0 deletions
14
cli/dts/lib.deno.ns.d.ts
vendored
14
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -2441,6 +2441,20 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* If `httpConn.nextRequest()` encounters an error or returns `null`
|
* If `httpConn.nextRequest()` encounters an error or returns `null`
|
||||||
* then the underlying HttpConn resource is closed automatically.
|
* 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;
|
export function serveHttp(conn: Conn): HttpConn;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue