diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index b5b74996378410..34fd6b7aa94736 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -53,7 +53,7 @@ When implementing a worker pool, use the [`AsyncResource`][] API to inform diagnostic tools (e.g. in order to provide asynchronous stack traces) about the correlation between tasks and their outcomes. -## worker.isMainThread +## `worker.isMainThread` @@ -74,7 +74,7 @@ if (isMainThread) { } ``` -## worker.moveMessagePortToContext(port, contextifiedSandbox) +## `worker.moveMessagePortToContext(port, contextifiedSandbox)` @@ -98,7 +98,7 @@ However, the created `MessagePort` will no longer inherit from [`EventEmitter`][], and only [`port.onmessage()`][] can be used to receive events using it. -## worker.parentPort +## `worker.parentPort` @@ -129,7 +129,7 @@ if (isMainThread) { } ``` -## worker.receiveMessageOnPort(port) +## `worker.receiveMessageOnPort(port)` @@ -157,7 +157,7 @@ console.log(receiveMessageOnPort(port2)); When this function is used, no `'message'` event will be emitted and the `onmessage` listener will not be invoked. -## worker.SHARE_ENV +## `worker.SHARE_ENV` @@ -176,7 +176,7 @@ new Worker('process.env.SET_IN_WORKER = "foo"', { eval: true, env: SHARE_ENV }) }); ``` -## worker.threadId +## `worker.threadId` @@ -187,7 +187,7 @@ An integer identifier for the current thread. On the corresponding worker object (if there is any), it is available as [`worker.threadId`][]. This value is unique for each [`Worker`][] instance inside a single process. -## worker.workerData +## `worker.workerData` @@ -208,7 +208,7 @@ if (isMainThread) { } ``` -## Class: MessageChannel +## Class: `MessageChannel` @@ -228,7 +228,7 @@ port2.postMessage({ foo: 'bar' }); // Prints: received { foo: 'bar' } from the `port1.on('message')` listener ``` -## Class: MessagePort +## Class: `MessagePort` @@ -243,7 +243,7 @@ structured data, memory regions and other `MessagePort`s between different With the exception of `MessagePort`s being [`EventEmitter`][]s rather than [`EventTarget`][]s, this implementation matches [browser `MessagePort`][]s. -### Event: 'close' +### Event: `'close'` @@ -265,7 +265,7 @@ port1.postMessage('foobar'); port1.close(); ``` -### Event: 'message' +### Event: `'message'` @@ -278,7 +278,7 @@ input of [`port.postMessage()`][]. Listeners on this event will receive a clone of the `value` parameter as passed to `postMessage()` and no further arguments. -### port.close() +### `port.close()` @@ -290,7 +290,7 @@ This method can be called when no further communication will happen over this The [`'close'` event][] will be emitted on both `MessagePort` instances that are part of the channel. -### port.postMessage(value\[, transferList\]) +### `port.postMessage(value[, transferList])` @@ -371,7 +371,7 @@ posting without having side effects. For more information on the serialization and deserialization mechanisms behind this API, see the [serialization API of the `v8` module][v8.serdes]. -### port.ref() +### `port.ref()` @@ -384,7 +384,7 @@ If listeners are attached or removed using `.on('message')`, the port will be `ref()`ed and `unref()`ed automatically depending on whether listeners for the event exist. -### port.start() +### `port.start()` @@ -399,7 +399,7 @@ Node.js also diverges in its handling of `.onmessage`. Setting it will automatically call `.start()`, but unsetting it will let messages queue up until a new handler is set or the port is discarded. -### port.unref() +### `port.unref()` @@ -412,7 +412,7 @@ If listeners are attached or removed using `.on('message')`, the port will be `ref()`ed and `unref()`ed automatically depending on whether listeners for the event exist. -## Class: Worker +## Class: `Worker` @@ -487,7 +487,7 @@ if (isMainThread) { } ``` -### new Worker(filename\[, options\]) +### `new Worker(filename[, options])` * `filename` {string} The path to the Worker’s main script. Must be either an absolute path or a relative path (i.e. relative to the @@ -520,7 +520,7 @@ if (isMainThread) { will be thrown if the object cannot be cloned (e.g. because it contains `function`s). -### Event: 'error' +### Event: `'error'` @@ -530,7 +530,7 @@ added: v10.5.0 The `'error'` event is emitted if the worker thread throws an uncaught exception. In that case, the worker will be terminated. -### Event: 'exit' +### Event: `'exit'` @@ -542,7 +542,7 @@ exited by calling [`process.exit()`][], the `exitCode` parameter will be the passed exit code. If the worker was terminated, the `exitCode` parameter will be `1`. -### Event: 'message' +### Event: `'message'` @@ -553,7 +553,7 @@ The `'message'` event is emitted when the worker thread has invoked [`require('worker_threads').parentPort.postMessage()`][]. See the [`port.on('message')`][] event for more details. -### Event: 'online' +### Event: `'online'` @@ -561,7 +561,7 @@ added: v10.5.0 The `'online'` event is emitted when the worker thread has started executing JavaScript code. -### worker.postMessage(value\[, transferList\]) +### `worker.postMessage(value[, transferList])` @@ -573,7 +573,7 @@ Send a message to the worker that will be received via [`require('worker_threads').parentPort.on('message')`][]. See [`port.postMessage()`][] for more details. -### worker.ref() +### `worker.ref()` @@ -583,7 +583,7 @@ Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker will behavior). If the worker is `ref()`ed, calling `ref()` again will have no effect. -### worker.stderr +### `worker.stderr` @@ -595,7 +595,7 @@ inside the worker thread. If `stderr: true` was not passed to the [`Worker`][] constructor, then data will be piped to the parent thread's [`process.stderr`][] stream. -### worker.stdin +### `worker.stdin` @@ -606,7 +606,7 @@ If `stdin: true` was passed to the [`Worker`][] constructor, this is a writable stream. The data written to this stream will be made available in the worker thread as [`process.stdin`][]. -### worker.stdout +### `worker.stdout` @@ -618,7 +618,7 @@ inside the worker thread. If `stdout: true` was not passed to the [`Worker`][] constructor, then data will be piped to the parent thread's [`process.stdout`][] stream. -### worker.terminate() +### `worker.terminate()` @@ -647,7 +647,7 @@ An integer identifier for the referenced thread. Inside the worker thread, it is available as [`require('worker_threads').threadId`][]. This value is unique for each `Worker` instance inside a single process. -### worker.unref() +### `worker.unref()`