summaryrefslogtreecommitdiff
path: root/std/http
diff options
context:
space:
mode:
authorAndy Hayden <andyhayden1@gmail.com>2019-10-28 12:58:35 -0700
committerRy Dahl <ry@tinyclouds.org>2019-10-28 15:58:35 -0400
commitf484776384ad7df35ab7626b7a673f3902a6cfaa (patch)
treecb74f31550dc666ec75f5a2f95d61dc69931cb16 /std/http
parent71efe6f2c530d1cb9e8a2679f5778e2c034a9d0d (diff)
Use top-level for-await in various places (#3217)
Diffstat (limited to 'std/http')
-rw-r--r--std/http/http_bench.ts10
-rw-r--r--std/http/racing_server.ts50
2 files changed, 26 insertions, 34 deletions
diff --git a/std/http/http_bench.ts b/std/http/http_bench.ts
index 06043f9e4..462e15e0e 100644
--- a/std/http/http_bench.ts
+++ b/std/http/http_bench.ts
@@ -5,11 +5,7 @@ const addr = Deno.args[1] || "127.0.0.1:4500";
const server = serve(addr);
const body = new TextEncoder().encode("Hello World");
-async function main(): Promise<void> {
- console.log(`http://${addr}/`);
- for await (const req of server) {
- req.respond({ body });
- }
+console.log(`http://${addr}/`);
+for await (const req of server) {
+ req.respond({ body });
}
-
-main();
diff --git a/std/http/racing_server.ts b/std/http/racing_server.ts
index 9d118dc6d..17d982460 100644
--- a/std/http/racing_server.ts
+++ b/std/http/racing_server.ts
@@ -19,32 +19,28 @@ async function largeRespond(request: ServerRequest, c: string): Promise<void> {
await request.respond({ status: 200, body: b });
}
-async function main(): Promise<void> {
- let step = 1;
- for await (const request of server) {
- switch (step) {
- case 1:
- // Try to wait long enough.
- // For pipelining, this should cause all the following response
- // to block.
- delayedRespond(request);
- break;
- case 2:
- // HUGE body.
- largeRespond(request, "a");
- break;
- case 3:
- // HUGE body.
- largeRespond(request, "b");
- break;
- default:
- request.respond({ status: 200, body: body4 });
- break;
- }
- step++;
+console.log("Racing server listening...\n");
+
+let step = 1;
+for await (const request of server) {
+ switch (step) {
+ case 1:
+ // Try to wait long enough.
+ // For pipelining, this should cause all the following response
+ // to block.
+ delayedRespond(request);
+ break;
+ case 2:
+ // HUGE body.
+ largeRespond(request, "a");
+ break;
+ case 3:
+ // HUGE body.
+ largeRespond(request, "b");
+ break;
+ default:
+ request.respond({ status: 200, body: body4 });
+ break;
}
+ step++;
}
-
-main();
-
-console.log("Racing server listening...\n");