Skip to content
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

Remove timeout with AbortController from procedure #1936

Closed
Closed
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
15 changes: 3 additions & 12 deletions lib/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Procedure {
this.deprecated = exp.deprecated || false;
this.assert = exp.assert || null;
this.examples = exp.examples || null;
this.onAborted = exp.onAborted || null;
}

async enter() {
Expand All @@ -57,7 +58,7 @@ class Procedure {
}

async invoke(context, args = {}) {
const { parameters, validate, returns, errors, timeout } = this;
const { parameters, validate, returns, errors } = this;
const exp = this.script(context);
const method = typeof exp === 'object' ? exp[this.methodName] : exp;
if (parameters) {
Expand All @@ -66,17 +67,7 @@ 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 result = await method(args);
if (metarhia.metautil.isError(result)) {
if (result instanceof DomainError) result = result.toError(errors);
return result;
Expand Down