Skip to content

Commit 3ccc9a9

Browse files
ppisljarlukasolson
authored andcommitted
cancellation of interpreter execution (#40238)
* add AbortSignal to interpreter * adding AbortSignal to visualize_loader * adding AbortSignal to embeddables and dashboard * passing AbortSignal to courier request handler * Remove abort signal from dashboard and move to handler, and abort fetches when necessary * Remove the rest of the references to abort signal in dashboard * Revert changes to dashboard_app * Remove code related to canceling visualize requests and only keep stuff for canceling interpreter * Use createError
1 parent b7ae57b commit 3ccc9a9

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/legacy/core_plugins/data/public/expressions/expressions_service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type getInitialContextFunction = () => InitialContextObject;
4141
export interface Handlers {
4242
getInitialContext: getInitialContextFunction;
4343
inspectorAdapters?: Adapters;
44+
abortSignal?: AbortSignal;
4445
}
4546

4647
type Context = object;

src/legacy/ui/public/vis/request_handlers/courier.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const CourierRequestHandlerProvider = function () {
4242
inspectorAdapters,
4343
queryFilter
4444
}) {
45-
4645
// Create a new search source that inherits the original search source
4746
// but has the appropriate timeRange applied via a filter.
4847
// This is a temporary solution until we properly pass down all required

src/plugins/data/common/expressions/create_error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ export const createError = (err: any) => ({
2222
error: {
2323
stack: process.env.NODE_ENV === 'production' ? undefined : err.stack,
2424
message: typeof err === 'string' ? err : err.message,
25+
name: (err && err.name) || 'Error',
2526
},
2627
});

src/plugins/data/common/expressions/interpreter_provider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ export function interpreterProvider(config: any) {
7171
// if something failed, just return the failure
7272
if (getType(newContext) === 'error') return newContext;
7373

74+
// if execution was aborted return error
75+
if (handlers.abortSignal && handlers.abortSignal.aborted) {
76+
return createError({
77+
message: 'The expression was aborted.',
78+
name: 'AbortError',
79+
});
80+
}
81+
7482
// Continue re-invoking chain until it's empty
75-
return await invokeChain(chain, newContext);
83+
return invokeChain(chain, newContext);
7684
} catch (e) {
7785
// Everything that throws from a function will hit this
7886
// The interpreter should *never* fail. It should always return a `{type: error}` on failure

0 commit comments

Comments
 (0)