Skip to content

Commit

Permalink
chore: remove Progress.aborted (#5363)
Browse files Browse the repository at this point in the history
Most places use Progress.cleanupWhenAborted instead.
  • Loading branch information
dgozman committed Feb 9, 2021
1 parent 21c24c2 commit 002d8ef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/server/progress.ts
Expand Up @@ -27,7 +27,6 @@ export type ProgressResult = {
};

export interface Progress {
readonly aborted: Promise<void>;
log(message: string): void;
timeUntilDeadline(): number;
isRunning(): boolean;
Expand All @@ -52,11 +51,6 @@ export class ProgressController {
private _forceAbort: (error: Error) => void = () => {};
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.
private _cleanups: (() => any)[] = [];

Expand All @@ -70,7 +64,6 @@ export class ProgressController {
constructor() {
this._forceAbortPromise = new Promise((resolve, reject) => this._forceAbort = reject);
this._forceAbortPromise.catch(e => null); // Prevent unhandle promsie rejection.
this._abortedPromise = new Promise(resolve => this._aborted = resolve);
}

setLogName(logName: LogName) {
Expand All @@ -91,7 +84,6 @@ export class ProgressController {
this._state = 'running';

const progress: Progress = {
aborted: this._abortedPromise,
log: message => {
if (this._state === 'running')
this._logRecording.push(message);
Expand Down Expand Up @@ -133,7 +125,6 @@ export class ProgressController {
this._logRecording = [];
return result;
} catch (e) {
this._aborted();
clearTimeout(timer);
this._state = 'aborted';
await Promise.all(this._cleanups.splice(0).map(cleanup => runCleanup(cleanup)));
Expand Down
4 changes: 2 additions & 2 deletions src/server/transport.ts
Expand Up @@ -55,9 +55,9 @@ export class WebSocketTransport implements ConnectionTransport {
progress.log(`<ws connecting> ${url}`);
const transport = new WebSocketTransport(progress, url);
let success = false;
progress.aborted.then(() => {
progress.cleanupWhenAborted(async () => {
if (!success)
transport.closeAndWait().catch(e => null);
await transport.closeAndWait().catch(e => null);
});
await new Promise<WebSocketTransport>((fulfill, reject) => {
transport._ws.addEventListener('open', async () => {
Expand Down

0 comments on commit 002d8ef

Please sign in to comment.