summaryrefslogtreecommitdiff
path: root/website/manual.md
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2019-07-16 13:19:26 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-07-16 00:19:26 -0400
commit9c454998646ef49f652bc919f53503ed07a1c55c (patch)
treea6275bdefa3da50cae08c6c0f753d816215d9602 /website/manual.md
parentbd6ebb32df11641e148fd0adca41e7188f16afce (diff)
Support window.onload (#2643)
Diffstat (limited to 'website/manual.md')
-rw-r--r--website/manual.md23
1 files changed, 11 insertions, 12 deletions
diff --git a/website/manual.md b/website/manual.md
index 4025e5acc..0424a2d25 100644
--- a/website/manual.md
+++ b/website/manual.md
@@ -425,7 +425,7 @@ $ deno run --allow-net=deno.land allow-net-whitelist-example.ts
Example:
```ts
-async function main() {
+window.onload = async function() {
// create subprocess
const p = Deno.run({
args: ["echo", "hello"]
@@ -433,9 +433,7 @@ async function main() {
// await its completion
await p.status();
-}
-
-main();
+};
```
Run it:
@@ -445,12 +443,17 @@ $ deno run --allow-run ./subprocess_simple.ts
hello
```
+Here a function is assigned to `window.onload`. This function is called after
+the main script is loaded. This is the same as
+[onload](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload)
+of the browsers, and it can be used as the main entrypoint.
+
By default when you use `Deno.run()` subprocess inherits `stdin`, `stdout` and
`stderr` of parent process. If you want to communicate with started subprocess
you can use `"piped"` option.
```ts
-async function main() {
+window.onload = async function() {
const decoder = new TextDecoder();
const fileNames = Deno.args.slice(1);
@@ -479,9 +482,7 @@ async function main() {
}
Deno.exit(code);
-}
-
-main();
+};
```
When you run it:
@@ -833,14 +834,12 @@ Example:
import { serve } from "http/server.ts";
-async function main() {
+window.onload = async function() {
const body = new TextEncoder().encode("Hello World\n");
for await (const req of serve(":8000")) {
req.respond({ body });
}
-}
-
-main();
+};
```
```shell