diff options
author | Satya Rohith <me@satyarohith.com> | 2024-03-14 01:22:53 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 19:52:53 +0000 |
commit | bbc211906dcd5043af549250343cd7b42fb45043 (patch) | |
tree | 49868b4b758290dcec6668f95495ce9d79ad6a86 /ext/node/polyfills/worker_threads.ts | |
parent | 0fd8f549e2194223eca2d4b17f4e96cd5a0f5fd5 (diff) |
fix(ext/node): make worker ids sequential (#22884)
Diffstat (limited to 'ext/node/polyfills/worker_threads.ts')
-rw-r--r-- | ext/node/polyfills/worker_threads.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 4563f157f..49f2f3e3e 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -134,7 +134,6 @@ function toFileUrl(path: string): URL { : toFileUrlPosix(path); } -let threads = 0; const privateWorkerRef = Symbol("privateWorkerRef"); class NodeWorker extends EventEmitter { #id = 0; @@ -195,12 +194,10 @@ class NodeWorker extends EventEmitter { name = "[worker eval]"; } this.#name = name; - this.threadId = ++threads; const serializedWorkerMetadata = serializeJsMessageData({ workerData: options?.workerData, environmentData: environmentData, - threadId: this.threadId, }, options?.transferList ?? []); const id = op_create_worker( { @@ -216,6 +213,7 @@ class NodeWorker extends EventEmitter { serializedWorkerMetadata, ); this.#id = id; + this.threadId = id; this.#pollControl(); this.#pollMessages(); // https://nodejs.org/api/worker_threads.html#event-online @@ -391,6 +389,7 @@ let parentPort: ParentPort = null as any; internals.__initWorkerThreads = ( runningOnMainThread: boolean, + workerId, maybeWorkerMetadata, ) => { isMainThread = runningOnMainThread; @@ -414,11 +413,11 @@ internals.__initWorkerThreads = ( >(); parentPort = self as ParentPort; + threadId = workerId; if (maybeWorkerMetadata) { const { 0: metadata, 1: _ } = maybeWorkerMetadata; workerData = metadata.workerData; environmentData = metadata.environmentData; - threadId = metadata.threadId; } defaultExport.workerData = workerData; defaultExport.parentPort = parentPort; |