Explorar el Código

Avoids any usage for setTimeout/setInterval

main
Eric Amodio hace 2 años
padre
commit
df7dd9f4ab
Se han modificado 6 ficheros con 28 adiciones y 19 borrados
  1. +1
    -1
      src/commands/closeUnchangedFiles.ts
  2. +9
    -3
      src/partners.ts
  3. +5
    -2
      src/statusbar/statusBarController.ts
  4. +8
    -8
      src/system/function.ts
  5. +4
    -4
      src/system/promise.ts
  6. +1
    -1
      src/trackers/documentTracker.ts

+ 1
- 1
src/commands/closeUnchangedFiles.ts Ver fichero

@ -130,7 +130,7 @@ export class CloseUnchangedFilesCommand extends Command {
private waitForEditorChange(timeout: number = 500): Promise<TextEditor | undefined> {
return new Promise<TextEditor | undefined>(resolve => {
let timer: any | undefined;
let timer: ReturnTypean><typeof setTimeout> | undefined;
this._onEditorChangedFn = (editor: TextEditor | undefined) => {
if (timer != null) {

+ 9
- 3
src/partners.ts Ver fichero

@ -12,12 +12,15 @@ export async function installExtension(
vsix?: Uri,
): Promise<Extension<T> | undefined> {
try {
let timer: any = 0;
let timer: ReturnType<typeof setTimeout> | undefined = undefined;
const extension = new Promise<Extension<any> | undefined>(resolve => {
const disposable = extensions.onDidChange(() => {
const extension = extensions.getExtension(extensionId);
if (extension != null) {
clearTimeout(timer);
if (timer != null) {
clearTimeout(timer);
timer = undefined;
}
disposable.dispose();
resolve(extension);
@ -33,7 +36,10 @@ export async function installExtension(
await commands.executeCommand(BuiltInCommands.InstallExtension, vsix ?? extensionId);
// Wait for extension activation until timeout expires
timer = setTimeout(() => tokenSource.cancel(), timeout);
timer = setTimeout(() => {
timer = undefined;
tokenSource.cancel();
}, timeout);
return extension;
} catch {

+ 5
- 2
src/statusbar/statusBarController.ts Ver fichero

@ -25,7 +25,7 @@ import { LinesChangeEvent } from '../trackers/gitLineTracker';
export class StatusBarController implements Disposable {
private _pullRequestCancellation: CancellationTokenSource | undefined;
private _tooltipCancellation: CancellationTokenSource | undefined;
private _tooltipDelayTimer: any | undefined;
private _tooltipDelayTimer: ReturnTypean><typeof setTimeout> | undefined;
private readonly _disposable: Disposable;
private _statusBarBlame: StatusBarItem | undefined;
@ -305,10 +305,13 @@ export class StatusBarController implements Disposable {
this._statusBarBlame.tooltip = tooltip;
clearTimeout(this._tooltipDelayTimer);
if (this._tooltipDelayTimer != null) {
clearTimeout(this._tooltipDelayTimer);
}
this._tooltipCancellation?.cancel();
this._tooltipDelayTimer = setTimeout(() => {
this._tooltipDelayTimer = undefined;
this._tooltipCancellation = new CancellationTokenSource();
void this.updateCommitTooltip(

+ 8
- 8
src/system/function.ts Ver fichero

@ -152,26 +152,26 @@ export function propOf>(o: T, key: K) {
}
export function interval(fn: (...args: any[]) => void, ms: number): Disposable {
let timer: any | undefined;
let timer: ReturnTypean><typeof setInterval> | undefined;
const disposable = {
dispose: () => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
},
};
timer = globalThis.setInterval(fn, ms);
timer = setInterval(fn, ms);
return disposable;
}
export function progress<T>(promise: Promise<T>, intervalMs: number, onProgress: () => boolean): Promise<T> {
return new Promise((resolve, reject) => {
let timer: any | undefined;
timer = globalThis.setInterval(() => {
let timer: ReturnTypean><typeof setInterval> | undefined;
timer = setInterval(() => {
if (onProgress()) {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
@ -180,7 +180,7 @@ export function progress(promise: Promise, intervalMs: number, onProgress:
promise.then(
() => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}
@ -188,7 +188,7 @@ export function progress(promise: Promise, intervalMs: number, onProgress:
resolve(promise);
},
ex => {
if (timer !== undefined) {
if (timer != null) {
clearInterval(timer);
timer = undefined;
}

+ 4
- 4
src/system/promise.ts Ver fichero

@ -28,9 +28,9 @@ export function cancellable(
return new Promise((resolve, reject) => {
let fulfilled = false;
let timer: any | undefined;
let timer: ReturnTypean><typeof setTimeout> | undefined;
if (typeof timeoutOrToken === 'number') {
timer = globalThis.setTimeout(() => {
timer = setTimeout(() => {
if (typeof options.onDidCancel === 'function') {
options.onDidCancel(resolve, reject);
} else {
@ -52,14 +52,14 @@ export function cancellable(
promise.then(
() => {
fulfilled = true;
if (timer !== undefined) {
if (timer != null) {
clearTimeout(timer);
}
resolve(promise);
},
ex => {
fulfilled = true;
if (timer !== undefined) {
if (timer != null) {
clearTimeout(timer);
}
reject(ex);

+ 1
- 1
src/trackers/documentTracker.ts Ver fichero

@ -96,7 +96,7 @@ export class DocumentTracker implements Disposable {
this.onActiveTextEditorChanged(window.activeTextEditor);
}
private _timer: any | undefined;
private _timer: ReturnTypean><typeof setTimeout> | undefined;
private onActiveTextEditorChanged(editor: TextEditor | undefined) {
if (editor != null && !isTextEditor(editor)) return;

Cargando…
Cancelar
Guardar