From d27de12a42aa65d7544063ae43e9755c836747e8 Mon Sep 17 00:00:00 2001 From: Wroud Date: Thu, 7 Oct 2021 16:32:21 +0300 Subject: [PATCH] fix(plugin-data-viewer): CB-1305 fetch cancellation --- .../ConnectionExecutionContext.ts | 5 ++++- .../core-executor/src/TaskScheduler/Task.ts | 13 +++++++++++-- .../plugin-data-viewer/src/ContainerDataSource.ts | 7 +++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/webapp/packages/core-connections/src/ConnectionExecutionContext/ConnectionExecutionContext.ts b/webapp/packages/core-connections/src/ConnectionExecutionContext/ConnectionExecutionContext.ts index af82ec540f..733f973b63 100644 --- a/webapp/packages/core-connections/src/ConnectionExecutionContext/ConnectionExecutionContext.ts +++ b/webapp/packages/core-connections/src/ConnectionExecutionContext/ConnectionExecutionContext.ts @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. */ -import { makeObservable, observable } from 'mobx'; +import { computed, makeObservable, observable } from 'mobx'; import type { ITask, TaskScheduler } from '@cloudbeaver/core-executor'; @@ -37,6 +37,9 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext { this.currentTask = null; makeObservable(this, { currentTask: observable.ref, + context: computed, + executing: computed, + cancellable: computed, }); } diff --git a/webapp/packages/core-executor/src/TaskScheduler/Task.ts b/webapp/packages/core-executor/src/TaskScheduler/Task.ts index 080019bde6..16d8201f2c 100644 --- a/webapp/packages/core-executor/src/TaskScheduler/Task.ts +++ b/webapp/packages/core-executor/src/TaskScheduler/Task.ts @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. */ -import { makeObservable, observable } from 'mobx'; +import { computed, makeObservable, observable } from 'mobx'; import type { ITask } from './ITask'; @@ -15,7 +15,11 @@ export class Task implements ITask { executing: boolean; get cancellable(): boolean { - return !this.cancelled && (!this.executing || !!this.externalCancel); + if (this.cancelled) { + return false; + } + + return !this.executing || this.externalCancel !== undefined; } private resolve!: (value: TValue) => void; @@ -38,6 +42,7 @@ export class Task implements ITask { this.executing = false; makeObservable(this, { + cancellable: computed, cancelled: observable, executing: observable, }); @@ -107,6 +112,10 @@ export class Task implements ITask { } cancel(): Promise | void { + if (this.cancelled) { + return; + } + this.cancelled = true; if (!this.executing) { diff --git a/webapp/packages/plugin-data-viewer/src/ContainerDataSource.ts b/webapp/packages/plugin-data-viewer/src/ContainerDataSource.ts index 2639eebeec..db1b513db5 100644 --- a/webapp/packages/plugin-data-viewer/src/ContainerDataSource.ts +++ b/webapp/packages/plugin-data-viewer/src/ContainerDataSource.ts @@ -6,6 +6,8 @@ * you may not use this file except in compliance with the License. */ +import { computed, makeObservable, observable } from 'mobx'; + import type { ConnectionExecutionContextService, IConnectionExecutionContext, IConnectionExecutionContextInfo } from '@cloudbeaver/core-connections'; import type { NotificationService } from '@cloudbeaver/core-events'; import type { ITask } from '@cloudbeaver/core-executor'; @@ -38,6 +40,11 @@ export class ContainerDataSource extends DatabaseDataSource