Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/JavaScriptEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type EvalResponse = {
timeout?: boolean // if true the promise is rejected due to timeout
starvation?: boolean // if true the promise is rejected due to lack of child process
message?: string; // if promise rejected due to a caught exception this will be set
stack?: string;
elapsed?: number; // the elapsed time in ms to process the work item
maxQueueDepthExceeded?: boolean // if true the promise is rejected because the queue is full
}
Expand Down Expand Up @@ -137,15 +138,17 @@ export class JavaScriptEvaluator {
.catch(err => {
console.log(err);
reject({
message: err.message
message: err.message,
stack: err.stack
Comment on lines 138 to +142
});
});
}
}
catch (err: any) {
console.log(err);
reject({
Comment on lines 147 to 149
message: err.message
message: err.message,
stack: err.stack
});
}
});
Expand All @@ -169,6 +172,7 @@ export class JavaScriptEvaluator {
};
if(this.queue.length >= this.options.maxQueueDepth) {
reject({ maxQueueDepthExceeded: true, elapsed: 0 });
return;
}
Comment on lines 173 to 176
this.queue.push(workItem);
this.processQueue(options);
Expand Down Expand Up @@ -220,7 +224,7 @@ export class JavaScriptEvaluator {
const workerPath = this.getWorkerPath();
// console.debug(`Worker path: ${workerPath}`);
const worker = child_process.fork(workerPath, { timeout: options.timeout, env: {} });
if (!worker.pid) {
if (worker.pid === undefined || worker.pid === null) {
Comment on lines 224 to +227
throw new Error('Failed to fork child process');
}
this.workers.push(worker);
Expand Down
Loading