-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ext/node): make worker ids sequential (#22884)
- Loading branch information
1 parent
0fd8f54
commit bbc2119
Showing
8 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,34 @@ | ||
import { | ||
isMainThread, | ||
parentPort, | ||
threadId, | ||
Worker, | ||
} from "node:worker_threads"; | ||
|
||
console.log("threadId", threadId); | ||
|
||
if (isMainThread) { | ||
const worker = new Worker(new URL(import.meta.url)); | ||
worker.on("message", (msg) => console.log("from worker:", msg)); | ||
worker.on("error", () => { | ||
throw new Error("error"); | ||
}); | ||
worker.on("exit", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Worker stopped with exit code ${code}`)); | ||
} | ||
}); | ||
} else if (threadId == 1) { | ||
const worker = new Worker(new URL(import.meta.url)); | ||
worker.on("message", (msg) => console.log("from worker:", msg)); | ||
worker.on("error", () => { | ||
throw new Error("error"); | ||
}); | ||
worker.on("exit", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Worker stopped with exit code ${code}`)); | ||
} | ||
}); | ||
} else { | ||
parentPort.postMessage("hello!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,4 @@ | ||
threadId 0 | ||
threadId 1 | ||
threadId 2 | ||
from worker: hello! |