MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / startWorker

Function startWorker

benchmark/src/benchmark.ts:92–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90}
91
92function startWorker() {
93 return new Promise<{worker: ChildProcess; url: string}>((resolve, reject) => {
94 const lines: string[] = [];
95 const child = fork(require.resolve('./worker'), [], {
96 execArgv: ['--expose-gc'],
97 stdio: ['pipe', 'pipe', process.stderr, 'ipc'],
98 });
99
100 child.once('error', reject);
101
102 child.on('message', msg => {
103 // eslint-disable-next-line @typescript-eslint/no-explicit-any
104 const url = (msg as any).url;
105 debug('Worker setup done, url is', url);
106 resolve({worker: child, url});
107 });
108
109 child.once('exit', (code, signal) => {
110 const msg = [
111 `Child exited with code ${code} signal ${signal}.`,
112 ...lines,
113 ].join('\n');
114 reject(new Error(msg));
115 });
116
117 const reader = byline.createStream(child.stdout as Readable);
118 reader.on('data', line => {
119 const str = line.toString();
120 debug('[worker] %s', str);
121 lines.push(str);
122 });
123 });
124}
125
126async function closeWorker(worker: ChildProcess) {
127 worker.kill();

Callers 1

runScenarioMethod · 0.85

Calls 6

resolveMethod · 0.80
resolveFunction · 0.50
rejectFunction · 0.50
onceMethod · 0.45
onMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected