-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to catch promise rejections from background refreshes (#637)
- Loading branch information
Showing
4 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
import process from 'node:process'; | ||
|
||
export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); | ||
|
||
export const disableExistingExceptionListeners = () => { | ||
const uncaughtExceptionListeners = process.rawListeners( | ||
'uncaughtException', | ||
) as NodeJS.UncaughtExceptionListener[]; | ||
const unhandledRejectionListeners = process.rawListeners( | ||
'unhandledRejection', | ||
) as NodeJS.UnhandledRejectionListener[]; | ||
|
||
process.removeAllListeners('uncaughtException'); | ||
process.removeAllListeners('unhandledRejection'); | ||
|
||
/* restore listeners */ | ||
return () => { | ||
uncaughtExceptionListeners.forEach((listener) => | ||
process.addListener('uncaughtException', listener), | ||
); | ||
unhandledRejectionListeners.forEach((listener) => | ||
process.addListener('unhandledRejection', listener), | ||
); | ||
}; | ||
}; |