aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/interval_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils/src/interval_utils.ts')
-rw-r--r--packages/utils/src/interval_utils.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/packages/utils/src/interval_utils.ts b/packages/utils/src/interval_utils.ts
index 62b79f2f5..ebecc7015 100644
--- a/packages/utils/src/interval_utils.ts
+++ b/packages/utils/src/interval_utils.ts
@@ -1,14 +1,18 @@
import * as _ from 'lodash';
export const intervalUtils = {
- setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number) {
+ setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number, onError: (err: Error) => void) {
let locked = false;
const intervalId = setInterval(async () => {
if (locked) {
return;
} else {
locked = true;
- await fn();
+ try {
+ await fn();
+ } catch (err) {
+ onError(err);
+ }
locked = false;
}
}, intervalMs);
@@ -17,4 +21,17 @@ export const intervalUtils = {
clearAsyncExcludingInterval(intervalId: NodeJS.Timer): void {
clearInterval(intervalId);
},
+ setInterval(fn: () => void, intervalMs: number, onError: (err: Error) => void) {
+ const intervalId = setInterval(() => {
+ try {
+ fn();
+ } catch (err) {
+ onError(err);
+ }
+ }, intervalMs);
+ return intervalId;
+ },
+ clearInterval(intervalId: NodeJS.Timer): void {
+ clearInterval(intervalId);
+ },
};