Skip to content

Commit

Permalink
worker: initial implementation
Browse files Browse the repository at this point in the history
Implement multi-threading support for most of the API.

Thanks to Stephen Belanger for reviewing this change in its
original form, to Olivia Hugger for reviewing the
documentation and some of the tests coming along with it,
and to Alexey Orlenko and Timothy Gu for reviewing other
parts of the tests.

Refs: ayojs/ayo#110
Refs: ayojs/ayo#114
Refs: ayojs/ayo#117
  • Loading branch information
addaleax committed May 22, 2018
1 parent 2a526eb commit 2b42361
Show file tree
Hide file tree
Showing 42 changed files with 1,669 additions and 73 deletions.
36 changes: 36 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,13 @@ but not provided in the `transferList` for that call.
An [ES6 module][] could not be resolved.

<a id="ERR_MISSING_PLATFORM_FOR_WORKER"></a>
### ERR_MISSING_PLATFORM_FOR_WORKER

The V8 platform used by this instance of Node does not support creating Workers.
This is caused by lack of embedder support for Workers. In particular, this
error will not occur with standard builds of Node.js.

<a id="ERR_MODULE_RESOLUTION_LEGACY"></a>
### ERR_MODULE_RESOLUTION_LEGACY

Expand Down Expand Up @@ -1722,6 +1729,35 @@ The fulfilled value of a linking promise is not a `vm.Module` object.
The current module's status does not allow for this operation. The specific
meaning of the error depends on the specific function.

<a id="ERR_WORKER_DOMAIN"></a>
### ERR_WORKER_DOMAIN

Used when trying to access the `domain` module inside of a worker thread.

<a id="ERR_WORKER_NEED_ABSOLUTE_PATH"></a>
### ERR_WORKER_NEED_ABSOLUTE_PATH

Used when the path for the main script of a worker is not an absolute path.

<a id="ERR_WORKER_OUT_OF_MEMORY"></a>
### ERR_WORKER_OUT_OF_MEMORY

Used when a worker hits its memory limit.

<a id="ERR_WORKER_UNAVAILABLE_FEATURE"></a>
### ERR_WORKER_UNAVAILABLE_FEATURE

<a id="ERR_WORKER_UNSERIALIZABLE_ERROR"></a>
### ERR_WORKER_UNSERIALIZABLE_ERROR

Used when all attempts at serializing an uncaught exception from a worker fail.

<a id="ERR_WORKER_UNSUPPORTED_EXTENSION"></a>
### ERR_WORKER_UNSUPPORTED_EXTENSION

Used when the pathname used for the main script of a worker has an
unknown file extension.

<a id="ERR_ZLIB_INITIALIZATION_FAILED"></a>
### ERR_ZLIB_INITIALIZATION_FAILED

Expand Down
29 changes: 29 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ added: v0.7.0
The `process.abort()` method causes the Node.js process to exit immediately and
generate a core file.

This feature is not available in [`Worker`][] threads.

## process.arch
<!-- YAML
added: v0.5.0
Expand Down Expand Up @@ -517,6 +519,8 @@ try {
}
```

This feature is not available in [`Worker`][] threads.

## process.config
<!-- YAML
added: v0.7.7
Expand Down Expand Up @@ -918,6 +922,8 @@ console.log(process.env.test);
// => 1
```

*Note*: `process.env` is read-only in [`Worker`][] threads.

## process.execArgv
<!-- YAML
added: v0.7.7
Expand Down Expand Up @@ -1030,6 +1036,9 @@ If it is necessary to terminate the Node.js process due to an error condition,
throwing an *uncaught* error and allowing the process to terminate accordingly
is safer than calling `process.exit()`.

*Note*: in [`Worker`][] threads, this function stops the current thread rather
than the current process.

## process.exitCode
<!-- YAML
added: v0.11.8
Expand Down Expand Up @@ -1204,6 +1213,8 @@ console.log(process.getgroups()); // [ 27, 30, 46, 1000 ]
This function is only available on POSIX platforms (i.e. not Windows or
Android).

This feature is not available in [`Worker`][] threads.

## process.kill(pid[, signal])
<!-- YAML
added: v0.0.6
Expand Down Expand Up @@ -1570,6 +1581,8 @@ if (process.getegid && process.setegid) {
This function is only available on POSIX platforms (i.e. not Windows or
Android).

This feature is not available in [`Worker`][] threads.

## process.seteuid(id)
<!-- YAML
added: v2.0.0
Expand Down Expand Up @@ -1597,6 +1610,8 @@ if (process.geteuid && process.seteuid) {
This function is only available on POSIX platforms (i.e. not Windows or
Android).

This feature is not available in [`Worker`][] threads.

## process.setgid(id)
<!-- YAML
added: v0.1.31
Expand Down Expand Up @@ -1624,6 +1639,8 @@ if (process.getgid && process.setgid) {
This function is only available on POSIX platforms (i.e. not Windows or
Android).

This feature is not available in [`Worker`][] threads.

## process.setgroups(groups)
<!-- YAML
added: v0.9.4
Expand All @@ -1640,6 +1657,8 @@ The `groups` array can contain numeric group IDs, group names or both.
This function is only available on POSIX platforms (i.e. not Windows or
Android).

This feature is not available in [`Worker`][] threads.

## process.setuid(id)
<!-- YAML
added: v0.1.28
Expand All @@ -1664,6 +1683,7 @@ if (process.getuid && process.setuid) {

This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in [`Worker`][] threads.

## process.setUncaughtExceptionCaptureCallback(fn)
<!-- YAML
Expand Down Expand Up @@ -1700,6 +1720,8 @@ a [Writable][] stream.
`process.stderr` differs from other Node.js streams in important ways, see
[note on process I/O][] for more information.

This feature is not available in [`Worker`][] threads.

## process.stdin

* {Stream}
Expand Down Expand Up @@ -1732,6 +1754,8 @@ In "old" streams mode the `stdin` stream is paused by default, so one
must call `process.stdin.resume()` to read from it. Note also that calling
`process.stdin.resume()` itself would switch stream to "old" mode.

This feature is not available in [`Worker`][] threads.

## process.stdout

* {Stream}
Expand All @@ -1750,6 +1774,8 @@ process.stdin.pipe(process.stdout);
`process.stdout` differs from other Node.js streams in important ways, see
[note on process I/O][] for more information.

This feature is not available in [`Worker`][] threads.

### A note on process I/O

`process.stdout` and `process.stderr` differ from other Node.js streams in
Expand Down Expand Up @@ -1865,6 +1891,8 @@ console.log(
);
```

This feature is not available in [`Worker`][] threads.

## process.uptime()
<!-- YAML
added: v0.5.0
Expand Down Expand Up @@ -2011,6 +2039,7 @@ cases:
[`require.resolve()`]: modules.html#modules_require_resolve_request_options
[`setTimeout(fn, 0)`]: timers.html#timers_settimeout_callback_delay_args
[`v8.setFlagsFromString()`]: v8.html#v8_v8_setflagsfromstring_flags
[`Worker`]: worker.html#worker_worker
[Android building]: https://github.com/nodejs/node/blob/master/BUILDING.md#androidandroid-based-devices-eg-firefox-os
[Child Process]: child_process.html
[Cluster]: cluster.html
Expand Down
Loading

0 comments on commit 2b42361

Please sign in to comment.