Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear hook timeout #243

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }>;
}
}