Deno 利用 pooledMap 并行处理 http 请求 注意:并 - Assbbs

Deno 利用 pooledMap 并行处理 http 请求 注意:并行不等于多线程,Deno中目前创建多线程应用唯一的方式是Workers。 import { pooledMap } from "https://deno.land/std@0.198.0/async/pool.ts"; function web request: Request : Res…

Deno 利用 pooledMap 并行处理 http 请求 注意:并行不等于多线程,Deno中目前创建多线程应用唯一的方式是Workers。 import { pooledMap } from "https://deno.land/std@0.198.0/async/pool.ts"; function web request: Request : Response { console.log request ; console.log new URL request.url ; const body = Your user-agent is: ${request.headers.get "user-agent" ?? "Unknown" } ; return new Response body, { status: 200, } } pooledMap // Deno.listenTls { // port: 8443, // certFile: "localhost.crt", // keyFile: "localhost.key", // alpnProtocols: "h2", "http/1.1" , // } ; window.navigator.hardwareConcurrency - 1, Deno.listen { port: 8080 } , async conn: Deno.Conn => { for await const event of Deno.serveHttp conn { event.respondWith web event.request ; } } ;