Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix the retry functionality and increase coverage (#787)
- Loading branch information
1 parent
ca8c560
commit 0501e00
Showing
7 changed files
with
126 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* istanbul ignore file: used for webpack */ | ||
|
||
export default (moduleObject: NodeModule, moduleId: string): unknown => { | ||
return moduleObject.require(moduleId); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import EventEmitter = require('events'); | ||
|
||
type Origin = EventEmitter; | ||
type Event = string | symbol; | ||
type Fn = (...args: unknown[]) => void; | ||
|
||
interface Handler { | ||
origin: Origin; | ||
event: Event; | ||
fn: Fn; | ||
} | ||
|
||
interface Unhandler { | ||
once: (origin: Origin, event: Event, fn: Fn) => void; | ||
unhandleAll: () => void; | ||
} | ||
|
||
// When attaching listeners, it's very easy to forget about them. | ||
// Especially if you do error handling and set timeouts. | ||
// So instead of checking if it's proper to throw an error on every timeout ever, | ||
// use this simple tool which will remove all listeners you have attached. | ||
export default (): Unhandler => { | ||
const handlers: Handler[] = []; | ||
|
||
return { | ||
once(origin: Origin, event: Event, fn: Fn) { | ||
origin.once(event, fn); | ||
handlers.push({origin, event, fn}); | ||
}, | ||
|
||
unhandleAll() { | ||
for (const handler of handlers) { | ||
const {origin, event, fn} = handler; | ||
origin.removeListener(event, fn); | ||
} | ||
} | ||
}; | ||
}; |
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