Skip to content

Commit 5ba0926

Browse files
committed
Add explicit null checks (fixes microsoft/monaco-editor#1376)
1 parent 6c74e97 commit 5ba0926

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/vs/base/common/async.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,14 @@ export class Delayer<T> implements IDisposable {
184184
private timeout: any;
185185
private completionPromise: Promise<any> | null;
186186
private doResolve: ((value?: any | Promise<any>) => void) | null;
187-
private doReject?: (err: any) => void;
187+
private doReject: ((err: any) => void) | null;
188188
private task: ITask<T | Promise<T>> | null;
189189

190190
constructor(public defaultDelay: number) {
191191
this.timeout = null;
192192
this.completionPromise = null;
193193
this.doResolve = null;
194+
this.doReject = null;
194195
this.task = null;
195196
}
196197

@@ -205,16 +206,20 @@ export class Delayer<T> implements IDisposable {
205206
}).then(() => {
206207
this.completionPromise = null;
207208
this.doResolve = null;
208-
const task = this.task!;
209-
this.task = null;
210-
211-
return task();
209+
if (this.task) {
210+
const task = this.task;
211+
this.task = null;
212+
return task();
213+
}
214+
return undefined;
212215
});
213216
}
214217

215218
this.timeout = setTimeout(() => {
216219
this.timeout = null;
217-
this.doResolve!(null);
220+
if (this.doResolve) {
221+
this.doResolve(null);
222+
}
218223
}, delay);
219224

220225
return this.completionPromise;
@@ -228,7 +233,9 @@ export class Delayer<T> implements IDisposable {
228233
this.cancelTimeout();
229234

230235
if (this.completionPromise) {
231-
this.doReject!(errors.canceled());
236+
if (this.doReject) {
237+
this.doReject(errors.canceled());
238+
}
232239
this.completionPromise = null;
233240
}
234241
}

0 commit comments

Comments
 (0)