-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Francesco Rivola
committed
Feb 3, 2024
1 parent
607669a
commit e17a02d
Showing
9 changed files
with
75 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 +1,32 @@ | ||
import { EventEmitter } from "events"; | ||
|
||
type Counter = { | ||
incrementCounter: () => void; | ||
decrementCounter: () => void; | ||
getCount: () => number; | ||
registerSubscriberToCounterChanges(callback: (count: number) => void): void; | ||
} | ||
incrementCounter: () => void; | ||
decrementCounter: () => void; | ||
getCount: () => number; | ||
registerSubscriberToCounterChanges(callback: (count: number) => void): void; | ||
}; | ||
|
||
export function createCounter(): Counter { | ||
const eventEmitter: EventEmitter = new EventEmitter(); | ||
let count = 0; | ||
|
||
const eventEmitter: EventEmitter = new EventEmitter(); | ||
let count = 0; | ||
|
||
return { | ||
incrementCounter(): void { | ||
count++; | ||
eventEmitter.emit("counterUpdate", count); | ||
}, | ||
decrementCounter(): void { | ||
count--; | ||
eventEmitter.emit("counterUpdate", count); | ||
}, | ||
getCount(): number { | ||
return count; | ||
}, | ||
registerSubscriberToCounterChanges(callback: (count: number) => void): void { | ||
eventEmitter.on("counterUpdate", callback); | ||
}, | ||
}; | ||
return { | ||
incrementCounter(): void { | ||
count++; | ||
eventEmitter.emit("counterUpdate", count); | ||
}, | ||
decrementCounter(): void { | ||
count--; | ||
eventEmitter.emit("counterUpdate", count); | ||
}, | ||
getCount(): number { | ||
return count; | ||
}, | ||
registerSubscriberToCounterChanges( | ||
callback: (count: number) => void, | ||
): void { | ||
eventEmitter.on("counterUpdate", callback); | ||
}, | ||
}; | ||
} |
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,3 @@ | ||
export default class AbortError extends Error { | ||
export class AbortError extends Error { | ||
public name = "AbortError"; | ||
} |
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,3 @@ | ||
export default class ClosingError extends Error { | ||
public name = "ClosingError"; | ||
export class ClosingError extends Error { | ||
public name = "ClosingError"; | ||
} |
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,3 @@ | ||
export default class TimeoutClosingError extends Error { | ||
public name = "TimeoutClosingError"; | ||
export class TimeoutClosingError extends Error { | ||
public name = "TimeoutClosingError"; | ||
} |
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,2 +1,7 @@ | ||
import { fireAndForgetter } from "./fire-and-forgetter"; | ||
export default fireAndForgetter; | ||
export { | ||
fireAndForgetter as default, | ||
FireAndForgetter, | ||
} from "./fire-and-forgetter"; | ||
export * from "./errors/abort-error"; | ||
export * from "./errors/closing-error"; | ||
export * from "./errors/timeout-closing-error"; |
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