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

PR-URL: #20876
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
addaleax authored and targos committed Jun 13, 2018
1 parent 314b47d commit 109c92e
Show file tree
Hide file tree
Showing 44 changed files with 1,630 additions and 74 deletions.
23 changes: 23 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,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.js 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 @@ -1723,6 +1730,22 @@ 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_NEED_ABSOLUTE_PATH"></a>
### ERR_WORKER_NEED_ABSOLUTE_PATH

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

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

All attempts at serializing an uncaught exception from a worker thread failed.

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

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
27 changes: 27 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
```

`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()`.

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 @@ -1203,6 +1212,7 @@ 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
Expand Down Expand Up @@ -1306,6 +1316,9 @@ The _heap_ is where objects, strings, and closures are stored. Variables are
stored in the _stack_ and the actual JavaScript code resides in the
_code segment_.

When using [`Worker`][] threads, `rss` will be a value that is valid for the
entire process, while the other fields will only refer to the current thread.

## process.nextTick(callback[, ...args])
<!-- YAML
added: v0.1.26
Expand Down Expand Up @@ -1569,6 +1582,7 @@ 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
Expand Down Expand Up @@ -1596,6 +1610,7 @@ 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
Expand Down Expand Up @@ -1623,6 +1638,7 @@ 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
Expand All @@ -1639,6 +1655,7 @@ 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
Expand All @@ -1664,6 +1681,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 +1718,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 +1752,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 +1772,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 +1889,8 @@ console.log(
);
```

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

## process.uptime()
<!-- YAML
added: v0.5.0
Expand Down Expand Up @@ -1992,6 +2018,7 @@ cases:
[`ChildProcess`]: child_process.html#child_process_class_childprocess
[`Error`]: errors.html#errors_class_error
[`EventEmitter`]: events.html#events_class_eventemitter
[`Worker`]: worker.html#worker_worker
[`console.error()`]: console.html#console_console_error_data_args
[`console.log()`]: console.html#console_console_log_data_args
[`domain`]: domain.html
Expand Down
2 changes: 1 addition & 1 deletion doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const contextifiedSandbox = vm.createContext({ secret: 42 });

Creates a new ES `Module` object.

*Note*: Properties assigned to the `import.meta` object that are objects may
Properties assigned to the `import.meta` object that are objects may
allow the `Module` to access information outside the specified `context`, if the
object is created in the top level context. Use `vm.runInContext()` to create
objects in a specific context.
Expand Down
Loading

0 comments on commit 109c92e

Please sign in to comment.