Skip to content

Commit 7c38327

Browse files
doug-wadervagg
authored andcommitted
doc: update process.hrtime docs to include optional parameter
Adds more explicit documentation for the single optional parameter to process.hrtime to the process docs. PR-URL: #6585 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 0f17a28 commit 7c38327

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

doc/api/process.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ added: v0.1.13
798798
* `code` {Integer} The exit code. Defaults to `0`.
799799

800800
The `process.exit()` method instructs Node.js to terminate the process as
801-
quickly as possible with the specified exit `code`. If the `code` is omitted,
801+
quickly as possible with the specified exit `code`. If the `code` is omitted,
802802
exit uses either the 'success' code `0` or the value of `process.exitCode` if
803803
specified.
804804

@@ -811,7 +811,7 @@ process.exit(1);
811811
The shell that executed Node.js should see the exit code as `1`.
812812

813813
It is important to note that calling `process.exit()` will force the process to
814-
exit as quickly as possible *even if there are still asynchronous operations
814+
exit as quickly as possible *even if there are still asynchronous operations
815815
pending* that have not yet completed fully, *including* I/O operations to
816816
`process.stdout` and `process.stderr`.
817817

@@ -820,8 +820,8 @@ explicitly. The Node.js process will exit on it's own *if there is no additional
820820
work pending* in the event loop. The `process.exitCode` property can be set to
821821
tell the process which exit code to use when the process exits gracefully.
822822

823-
For instance, the following example illustrates a *misuse* of the
824-
`process.exit()` method that could lead to data printed to stdout being
823+
For instance, the following example illustrates a *misuse* of the
824+
`process.exit()` method that could lead to data printed to stdout being
825825
truncated and lost:
826826

827827
```js
@@ -863,7 +863,7 @@ A number which will be the process exit code, when the process either
863863
exits gracefully, or is exited via [`process.exit()`][] without specifying
864864
a code.
865865

866-
Specifying a code to [`process.exit(code)`][`process.exit()`] will override any
866+
Specifying a code to [`process.exit(code)`][`process.exit()`] will override any
867867
previous setting of `process.exitCode`.
868868

869869

@@ -947,15 +947,18 @@ if (process.getuid) {
947947
}
948948
```
949949

950-
## process.hrtime()
950+
## process.hrtime([time])
951951
<!-- YAML
952952
added: v0.7.6
953953
-->
954954

955955
Returns the current high-resolution real time in a `[seconds, nanoseconds]`
956-
tuple Array. It is relative to an arbitrary time in the past. It is not
957-
related to the time of day and therefore not subject to clock drift. The
958-
primary use is for measuring performance between intervals.
956+
tuple Array. `time` is an optional parameter that must be the result of a
957+
previous `process.hrtime()` call (and therefore, a real time in a
958+
`[seconds, nanoseconds]` tuple Array containing a previous time) to diff with
959+
the current time. These times are relative to an arbitrary time in the past,
960+
and not related to the time of day and therefore not subject to clock drift.
961+
The primary use is for measuring performance between intervals.
959962

960963
You may pass in the result of a previous call to `process.hrtime()` to get
961964
a diff reading, useful for benchmarks and measuring intervals:
@@ -973,6 +976,9 @@ setTimeout(() => {
973976
}, 1000);
974977
```
975978

979+
Constructing an array by some method other than calling `process.hrtime()` and
980+
passing the result to process.hrtime() will result in undefined behavior.
981+
976982

977983
## process.initgroups(user, extra_group)
978984
<!-- YAML

0 commit comments

Comments
 (0)