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