diff --git a/src/utils/AbortableOperation.ts b/src/utils/AbortableOperation.ts index d03f820a..fba71a8c 100644 --- a/src/utils/AbortableOperation.ts +++ b/src/utils/AbortableOperation.ts @@ -14,27 +14,40 @@ See the License for the specific language governing permissions and limitations under the License. */ +import {BaseObservableValue, ObservableValue} from "../observable/ObservableValue"; + export interface IAbortable { abort(); } -type RunFn = (setAbortable: (a: IAbortable) => typeof a) => T; +export type SetAbortableFn = (a: IAbortable) => typeof a; +export type SetProgressFn

= (progress: P) => void; +type RunFn = (setAbortable: SetAbortableFn, setProgress: SetProgressFn

) => T; -export class AbortableOperation { +export class AbortableOperation implements IAbortable { public readonly result: T; - private _abortable: IAbortable | null; + private _abortable?: IAbortable; + private _progress: ObservableValue

; - constructor(run: RunFn) { - this._abortable = null; - const setAbortable = abortable => { + constructor(run: RunFn) { + this._abortable = undefined; + const setAbortable: SetAbortableFn = abortable => { this._abortable = abortable; return abortable; }; - this.result = run(setAbortable); + this._progress = new ObservableValue

(undefined); + const setProgress: SetProgressFn

= (progress: P) => { + this._progress.set(progress); + }; + this.result = run(setAbortable, setProgress); + } + + get progress(): BaseObservableValue

{ + return this._progress; } abort() { this._abortable?.abort(); - this._abortable = null; + this._abortable = undefined; } }