Skip to content

Commit

Permalink
doc: console is asynchronous unless it's a file
Browse files Browse the repository at this point in the history
Mea culpa, looks like I forgot to update console.markdown in commit
dac1d38 ("doc: stdout/stderr can block when directed to file").
This commit rectifies that.

Refs: #5131
PR-URL: #5133
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Feb 22, 2016
1 parent 741b744 commit 9f7a543
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions doc/api/console.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ duplicate the browsers functionality exactly.

## Asynchronous vs Synchronous Consoles

The console functions are synchronous when the destination is a terminal or
a file (to avoid lost messages in case of premature exit) and asynchronous
when the destination is a pipe (to avoid blocking for long periods of time).

In the following example, stdout is non-blocking while stderr is blocking:

```
$ node script.js 2> error.log | tee info.log
```

Typically, the distinction between blocking/non-blocking is not important
unless an application is logging significant amounts of data. High volume
logging *should* use a `Console` instance that writes to a pipe.
The console functions are asynchronous unless the destination is a file.
Disks are fast and operating systems normally employ write-back caching;
it should be a very rare occurrence indeed that a write blocks, but it
is possible.

## Class: Console

Expand Down

0 comments on commit 9f7a543

Please sign in to comment.