3 ms·
I'm curious why the IIFE is even necessary in this case. There is already a top level await in the `for await` right? Looks fine IMHO once the IFFE is removed:
by emptysea 5y ago
I'm curious why the IIFE is even necessary in this case. There is already a top level await in the `for await` right?
Looks fine IMHO once the IFFE is removed:
for await (const conn of Deno.listen({ port: 4500 })) {
for await (const { respondWith } of Deno.serveHttp(conn)) {
respondWith(new Response("Hello World"));
}
}
Edit: Oh is it so it runs in concurrently and avoids the synchronous handling?
- maddyboo 5y agoYes I think the IIFE is there to avoid the inner loop blocking the outer loop. I think it looks better with the IIFE factored out into its own function: async function serve(conn) { for await (const { respondWith } of Deno.serveHttp(conn)) { respondWith(new Response("Hello World")); } } for await (const conn of Deno.listen({ port: 4500 })) { serve(conn); }