diff options
author | Andy Hayden <andyhayden1@gmail.com> | 2019-10-28 12:58:35 -0700 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-10-28 15:58:35 -0400 |
commit | f484776384ad7df35ab7626b7a673f3902a6cfaa (patch) | |
tree | cb74f31550dc666ec75f5a2f95d61dc69931cb16 /std/manual.md | |
parent | 71efe6f2c530d1cb9e8a2679f5778e2c034a9d0d (diff) |
Use top-level for-await in various places (#3217)
Diffstat (limited to 'std/manual.md')
-rw-r--r-- | std/manual.md | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/std/manual.md b/std/manual.md index 70ecdc9ac..fdace4605 100644 --- a/std/manual.md +++ b/std/manual.md @@ -312,8 +312,7 @@ and returns to the client anything it sends. ```ts const listener = Deno.listen({ port: 8080 }); console.log("listening on 0.0.0.0:8080"); -while (true) { - const conn = await listener.accept(); +for await (const conn of listener) { Deno.copy(conn, conn); } ``` @@ -353,26 +352,24 @@ Sometimes a program may want to revoke previously granted permissions. When a program, at a later stage, needs those permissions, it will fail. ```ts -const { permissions, open, remove } = Deno; - // lookup a permission -const status = await permissions.query({ name: "write" }); +const status = await Deno.permissions.query({ name: "write" }); if (status.state !== "granted") { throw new Error("need write permission"); } -const log = await open("request.log", "a+"); +const log = await Deno.open("request.log", "a+"); // revoke some permissions -await permissions.revoke({ name: "read" }); -await permissions.revoke({ name: "write" }); +await Deno.permissions.revoke({ name: "read" }); +await Deno.permissions.revoke({ name: "write" }); // use the log file const encoder = new TextEncoder(); await log.write(encoder.encode("hello\n")); // this will fail. -await remove("request.log"); +await Deno.remove("request.log"); ``` ### File server |