chore: remove Progress.aborted (#5363)
Most places use Progress.cleanupWhenAborted instead.
This commit is contained in:
parent
21c24c2357
commit
002d8ef5a7
|
|
@ -27,7 +27,6 @@ export type ProgressResult = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface Progress {
|
export interface Progress {
|
||||||
readonly aborted: Promise<void>;
|
|
||||||
log(message: string): void;
|
log(message: string): void;
|
||||||
timeUntilDeadline(): number;
|
timeUntilDeadline(): number;
|
||||||
isRunning(): boolean;
|
isRunning(): boolean;
|
||||||
|
|
@ -52,11 +51,6 @@ export class ProgressController {
|
||||||
private _forceAbort: (error: Error) => void = () => {};
|
private _forceAbort: (error: Error) => void = () => {};
|
||||||
private _forceAbortPromise: Promise<any>;
|
private _forceAbortPromise: Promise<any>;
|
||||||
|
|
||||||
// Promise and callback that resolve once the progress is aborted.
|
|
||||||
// This includes the force abort and also rejection of the task itself (failure).
|
|
||||||
private _aborted = () => {};
|
|
||||||
private _abortedPromise: Promise<void>;
|
|
||||||
|
|
||||||
// Cleanups to be run only in the case of abort.
|
// Cleanups to be run only in the case of abort.
|
||||||
private _cleanups: (() => any)[] = [];
|
private _cleanups: (() => any)[] = [];
|
||||||
|
|
||||||
|
|
@ -70,7 +64,6 @@ export class ProgressController {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._forceAbortPromise = new Promise((resolve, reject) => this._forceAbort = reject);
|
this._forceAbortPromise = new Promise((resolve, reject) => this._forceAbort = reject);
|
||||||
this._forceAbortPromise.catch(e => null); // Prevent unhandle promsie rejection.
|
this._forceAbortPromise.catch(e => null); // Prevent unhandle promsie rejection.
|
||||||
this._abortedPromise = new Promise(resolve => this._aborted = resolve);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogName(logName: LogName) {
|
setLogName(logName: LogName) {
|
||||||
|
|
@ -91,7 +84,6 @@ export class ProgressController {
|
||||||
this._state = 'running';
|
this._state = 'running';
|
||||||
|
|
||||||
const progress: Progress = {
|
const progress: Progress = {
|
||||||
aborted: this._abortedPromise,
|
|
||||||
log: message => {
|
log: message => {
|
||||||
if (this._state === 'running')
|
if (this._state === 'running')
|
||||||
this._logRecording.push(message);
|
this._logRecording.push(message);
|
||||||
|
|
@ -133,7 +125,6 @@ export class ProgressController {
|
||||||
this._logRecording = [];
|
this._logRecording = [];
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._aborted();
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
this._state = 'aborted';
|
this._state = 'aborted';
|
||||||
await Promise.all(this._cleanups.splice(0).map(cleanup => runCleanup(cleanup)));
|
await Promise.all(this._cleanups.splice(0).map(cleanup => runCleanup(cleanup)));
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ export class WebSocketTransport implements ConnectionTransport {
|
||||||
progress.log(`<ws connecting> ${url}`);
|
progress.log(`<ws connecting> ${url}`);
|
||||||
const transport = new WebSocketTransport(progress, url);
|
const transport = new WebSocketTransport(progress, url);
|
||||||
let success = false;
|
let success = false;
|
||||||
progress.aborted.then(() => {
|
progress.cleanupWhenAborted(async () => {
|
||||||
if (!success)
|
if (!success)
|
||||||
transport.closeAndWait().catch(e => null);
|
await transport.closeAndWait().catch(e => null);
|
||||||
});
|
});
|
||||||
await new Promise<WebSocketTransport>((fulfill, reject) => {
|
await new Promise<WebSocketTransport>((fulfill, reject) => {
|
||||||
transport._ws.addEventListener('open', async () => {
|
transport._ws.addEventListener('open', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue