Fix some examples in the manual
@@ -270,14 +270,12 @@ In this program each command-line argument is assumed to be a filename, the file
is opened, and printed to stdout.
```ts
-(async () => {
for (let i = 1; i < Deno.args.length; i++) {
let filename = Deno.args[i];
let file = await Deno.open(filename);
await Deno.copy(Deno.stdout, file);
file.close();
}
-})();
```
The `copy()` function here actually makes no more than the necessary kernel ->
@@ -297,17 +295,12 @@ This is an example of a simple server which accepts connections on port 8080,
and returns to the client anything it sends.
```ts
-const { listen, copy } = Deno;
-
-(async () => {
- const addr = "0.0.0.0:8080";
- const listener = listen("tcp", addr);
- console.log("listening on", addr);
+const listener = Deno.listen({ port: 8080 });
+console.log("listening on 0.0.0.0:8080");
while (true) {
const conn = await listener.accept();
- copy(conn, conn);
+ Deno.copy(conn, conn);
}
-})();
```
When this program is started, the user is prompted for permission to listen on
@@ -346,7 +339,6 @@ presented to the user.
```ts
const { permissions, revokePermission, open, remove } = Deno;
-(async () => {
// lookup a permission
if (!permissions().write) {
throw new Error("need write permission");
@@ -364,7 +356,6 @@ const { permissions, revokePermission, open, remove } = Deno;
// this will prompt for the write permission or fail.
await remove("request.log");
-})();
```
### File server
@@ -412,9 +403,7 @@ $ deno --allow-read=/etc https://deno.land/std/examples/cat.ts /etc/passwd
This is an example to restrict host.
```ts
-(async () => {
const result = await fetch("https://deno.land/std/examples/echo_server.ts");
-})();
```
```shell
@@ -428,7 +417,6 @@ $ deno --allow-net=deno.land allow-net-whitelist-example.ts
Example:
```ts
-window.onload = async function() {
// create subprocess
const p = Deno.run({
args: ["echo", "hello"]
@@ -436,7 +424,6 @@ window.onload = async function() {
// await its completion
await p.status();
-};
```
Run it:
@@ -456,9 +443,6 @@ By default when you use `Deno.run()` subprocess inherits `stdin`, `stdout` and
you can use `"piped"` option.
```ts
-window.onload = async function() {
- const decoder = new TextDecoder();
-
const fileNames = Deno.args.slice(1);
const p = Deno.run({
@@ -480,12 +464,11 @@ window.onload = async function() {
await Deno.stdout.write(rawOutput);
} else {
const rawError = await p.stderrOutput();
- const errorString = decoder.decode(rawError);
+ const errorString = new TextDecoder().decode(rawError);
console.log(errorString);
}
Deno.exit(code);
-};
```
When you run it:
