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

cancellation of interpreter execution #40238

Merged
merged 11 commits into from
Jul 30, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type getInitialContextFunction = () => InitialContextObject;
export interface Handlers {
getInitialContext: getInitialContextFunction;
inspectorAdapters?: Adapters;
abortSignal?: AbortSignal;
}

type Context = object;
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/public/vis/request_handlers/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const CourierRequestHandlerProvider = function () {
inspectorAdapters,
queryFilter
}) {

// Create a new search source that inherits the original search source
// but has the appropriate timeRange applied via a filter.
// This is a temporary solution until we properly pass down all required
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/expressions/create_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export const createError = (err: any) => ({
error: {
stack: process.env.NODE_ENV === 'production' ? undefined : err.stack,
message: typeof err === 'string' ? err : err.message,
name: (err && err.name) || 'Error',
},
});
10 changes: 9 additions & 1 deletion src/plugins/data/common/expressions/interpreter_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ export function interpreterProvider(config: any) {
// if something failed, just return the failure
if (getType(newContext) === 'error') return newContext;

// if execution was aborted return error
if (handlers.abortSignal && handlers.abortSignal.aborted) {
return createError({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this back to being createError because of the comment below:

The interpreter should never fail. It should always return a {type: error} on failure

The consumers can check if err.name === 'AbortError' and handle those failures differently than other failures.

message: 'The expression was aborted.',
name: 'AbortError',
});
}

// Continue re-invoking chain until it's empty
return await invokeChain(chain, newContext);
return invokeChain(chain, newContext);
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
// Everything that throws from a function will hit this
// The interpreter should *never* fail. It should always return a `{type: error}` on failure
Expand Down