Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -31,10 +31,10 @@ export interface TimeoutSubscriber<T> {
|
||||
* @param {number} timeout - timeout in milliseconds
|
||||
* @param {Promise} promise - the promise to subscribe to
|
||||
*/
|
||||
export function withTimeout<T>(timeout: number, promise: Promise<T>) {
|
||||
let onTimeHandler: (arg: T) => any = (arg) => {}
|
||||
let lateHandler: (arg: T) => any = (arg) => {}
|
||||
let timeoutHandler: () => any = () => {}
|
||||
export function withTimeout<T>(timeout: number, promise: Promise<T>): TimeoutSubscriber<T> {
|
||||
let onTimeHandler: (arg: T) => any = () => {} // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
let lateHandler: (arg: T) => any = () => {} // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
let timeoutHandler: () => any = () => {} // eslint-disable-line @typescript-eslint/no-empty-function
|
||||
|
||||
const sub = {
|
||||
onTime: handler => {
|
||||
@@ -54,7 +54,9 @@ export function withTimeout<T>(timeout: number, promise: Promise<T>) {
|
||||
let resolved = false
|
||||
setTimeout(() => {
|
||||
expired = true
|
||||
if ( !resolved ) timeoutHandler()
|
||||
if ( !resolved ) {
|
||||
timeoutHandler()
|
||||
}
|
||||
}, timeout)
|
||||
|
||||
const result: T = await promise
|
||||
@@ -67,7 +69,7 @@ export function withTimeout<T>(timeout: number, promise: Promise<T>) {
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
},
|
||||
} as TimeoutSubscriber<T>
|
||||
|
||||
return sub
|
||||
|
||||
Reference in New Issue
Block a user