Use top-level for-await in various places (#3217)

This commit is contained in:
Andy Hayden 2019-10-28 12:58:35 -07:00 committed by Ry Dahl
parent 71efe6f2c5
commit f484776384
9 changed files with 94 additions and 125 deletions

View file

@ -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++;
}
}
main();
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++;
}