Skip to content

Commit

Permalink
Optimize timeout for invoke
Browse files Browse the repository at this point in the history
PR-URL: #1958
  • Loading branch information
tshemsedinov committed Feb 5, 2024
1 parent a2a7ad0 commit b8d83ea
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ const handlers = {
return void parentPort.postMessage({ ...msg, data });
}
try {
let result;
if (timeout) {
const ac = new AbortController();
result = await Promise.race([
metarhia.metautil.timeout(timeout, ac.signal),
handler(args),
]);
ac.abort();
} else {
result = await handler(args);
}
let promise = handler(args);
if (timeout) promise = metarhia.metautil.timeoutify(promise, timeout);
const result = await promise;
const data = { id, status: 'done', result };
parentPort.postMessage({ ...msg, data });
} catch (err) {
Expand Down

0 comments on commit b8d83ea

Please sign in to comment.