Skip to content

Commit

Permalink
global Group example
Browse files Browse the repository at this point in the history
  • Loading branch information
j50n committed Feb 8, 2022
1 parent 4731d3f commit d0e90ef
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,33 @@ Finally, use the runner to execute a command.

```ts
try {
console.log(
runner.run({cmd: ["ls", "-la"]});
);
console.log(runner.run({ cmd: ["ls", "-la"] }));
} finally {
pg.close();
}
```

### A Simpler Alternative - The Global Group

It is not strictly necessary to create and close a local `Group`. If you don't
specify a group, `proc` will use the global `Group` that exists for the lifetime
of the Deno process.

```ts
const template = proc.runner(proc.emptyInput(), proc.stringOutput());
const runner: proc.Runner<void, string> = template(); // No Group is specified.
console.log(runner.run({ cmd: ["ls", "-la"] }));
```

Most of the time, `proc` can automatically clean up processes. In some cases
where the output of one process feeds into the input of another, the first
process won't be fully processed and therefore cannot be automatically shut
down. This can also happen if you don't fully process `AsyncIterable` output of
a process. This will result in resource leakage. If your program is short and
does not start many processes, or if you are sure that the way you are using
processes is well behaved (either non-streaming output or all output data is
fully consumed), you can use the short form safely.

# Key Concepts

## Process Basics
Expand Down

0 comments on commit d0e90ef

Please sign in to comment.