-
Notifications
You must be signed in to change notification settings - Fork 662
feat: add reuseChildProcess option to disable child process reuse
#4091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
c7fad2c
dc05059
de626a0
6a83263
ce053bf
5dd469c
e892e0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,20 +21,24 @@ export class ChildPool { | |
| free: { [key: string]: Child[] } = {}; | ||
| private opts: ChildPoolOpts; | ||
|
|
||
| private reuseChildProcess: boolean; | ||
|
|
||
| constructor({ | ||
| mainFile = supportCJS() | ||
| ? path.join(process.cwd(), 'dist/cjs/classes/main.js') | ||
| : path.join(process.cwd(), 'dist/esm/classes/main.js'), | ||
| useWorkerThreads, | ||
| workerForkOptions, | ||
| workerThreadsOptions, | ||
| reuseChildProcess = true, | ||
| }: ChildPoolOpts) { | ||
| this.opts = { | ||
| mainFile, | ||
| useWorkerThreads, | ||
| workerForkOptions, | ||
| workerThreadsOptions, | ||
| }; | ||
| this.reuseChildProcess = reuseChildProcess; | ||
| } | ||
|
|
||
| async retain(processFile: string): Promise<Child> { | ||
|
|
@@ -67,14 +71,18 @@ export class ChildPool { | |
| return child; | ||
| } catch (err) { | ||
| console.error(err); | ||
| this.release(child); | ||
| await this.release(child); | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| release(child: Child): void { | ||
| async release(child: Child): Promise<void> { | ||
| delete this.retained[child.pid]; | ||
| this.getFree(child.processFile).push(child); | ||
| if (this.reuseChildProcess) { | ||
| this.getFree(child.processFile).push(child); | ||
| } else { | ||
|
manast marked this conversation as resolved.
|
||
| await this.kill(child, 'SIGTERM'); | ||
| } | ||
|
Comment on lines
+79
to
+85
|
||
| } | ||
|
|
||
| remove(child: Child): void { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.