Skip to content

Commit

Permalink
fix: clear hook timeout (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Sep 8, 2021
1 parent bf2ea50 commit 0c32c65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,17 @@ export class Config implements IConfig {
}

const withTimeout = async (ms: number, promise: any) => {
const timeout = new Promise((_, reject) => setTimeout(() => reject(new Error(`Timed out after ${ms} ms.`)), ms))
return Promise.race([promise, timeout])
let id: NodeJS.Timeout
const timeout = new Promise((_, reject) => {
id = setTimeout(() => {
reject(new Error(`Timed out after ${ms} ms.`))
}, ms)
})

return Promise.race([promise, timeout]).then(result => {
clearTimeout(id)
return result
})
}

const successes = []
Expand Down Expand Up @@ -254,7 +263,7 @@ export class Config implements IConfig {

debug('done')
} catch (error) {
failures.push({plugin: p, error})
failures.push({plugin: p, error: error as Error})
if (error && error.oclif && error.oclif.exit !== undefined) throw error
this.warn(error, `runHook ${event}`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export namespace Hook {

export interface Result<T> {
successes: Array<{ result: T; plugin: Plugin }>;
failures: Array<{ error: typeof Error; plugin: Plugin }>;
failures: Array<{ error: Error; plugin: Plugin }>;
}
}

0 comments on commit 0c32c65

Please sign in to comment.