Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ of the custom deprecation.
The `*-deprecation` command-line flags only affect warnings that use the name
`'DeprecationWarning'`.

### Event: `'worker'`
<!-- YAML
added: REPLACEME
-->

* `worker` {Worker} The {Worker} that was created.

The `'worker'` event is emitted after a new {Worker} thread has been created.

#### Emitting custom warnings

See the [`process.emitWarning()`][process_emit_warning] method for issuing
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ class Worker extends EventEmitter {
};
// Actually start the new thread now that everything is in place.
this[kHandle].startThread();

process.nextTick(() => process.emit('worker', this));
}

[kOnExit](code, customErr, customErrReason) {
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-worker-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const {
Worker,
threadId: parentThreadId,
} = require('worker_threads');

process.on('worker', common.mustCall(({ threadId }) => {
assert.strictEqual(threadId, parentThreadId + 1);
}));

new Worker('', { eval: true });
1 change: 1 addition & 0 deletions tools/doc/type-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const customTypesMap = {
'vm.SourceTextModule': 'vm.html#vm_class_vm_sourcetextmodule',

'MessagePort': 'worker_threads.html#worker_threads_class_messageport',
'Worker': 'worker_threads.html#worker_threads_class_worker',

'X509Certificate': 'crypto.html#crypto_class_x509certificate',

Expand Down