1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

docs: Add async iterator alternative for Deno.serveHttp (#11850)

This commit is contained in:
Sebastien Filion 2021-08-26 11:06:58 -04:00 committed by GitHub
parent 23a9bc099d
commit 192af1e7bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}