Skip to content

Commit

Permalink
Refactor procedure timeout
Browse files Browse the repository at this point in the history
Refs: #1936
Refs: #1958
  • Loading branch information
tshemsedinov committed Feb 6, 2024
1 parent 294e8b0 commit 93f9527
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@ class Procedure {
if (!valid) return new Error('Invalid parameters type: ' + problems);
}
if (validate) await validate(args);
let result;
if (timeout) {
const ac = new AbortController();
result = await Promise.race([
metarhia.metautil.timeout(timeout, ac.signal),
method(args),
]);
ac.abort();
} else {
result = await method(args);
}
let promise = method(args);
if (timeout) promise = metarhia.metautil.timeoutify(promise, timeout);
let result = await promise;
if (metarhia.metautil.isError(result)) {
if (result instanceof DomainError) result = result.toError(errors);
return result;
Expand Down

0 comments on commit 93f9527

Please sign in to comment.