aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/resolve_after.ts
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-01 01:02:58 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-01 01:02:58 +0200
commitcac85db02ff00732cf75d473dc3411332f33d845 (patch)
tree5f244968a905eb3888434b3f60cbf05d2b652207 /src/lib/utils/resolve_after.ts
parenta7cf03c192470cbab13edeb1aec99e0c66dede10 (diff)
Apply formatting
Diffstat (limited to 'src/lib/utils/resolve_after.ts')
-rw-r--r--src/lib/utils/resolve_after.ts39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/lib/utils/resolve_after.ts b/src/lib/utils/resolve_after.ts
index 95a477e..5d35f1c 100644
--- a/src/lib/utils/resolve_after.ts
+++ b/src/lib/utils/resolve_after.ts
@@ -1,29 +1,26 @@
export type ResolveAfterPromise = {
- counter: () => void,
- promise: Promise<void>
+ counter: () => void;
+ promise: Promise<void>;
};
export const resolveAfter = function (timesUntilResolve: number): ResolveAfterPromise {
+ let counter = null;
+ let currentValue = 0;
- let counter = null;
- let currentValue = 0;
+ if (timesUntilResolve <= 0) {
+ throw new Error('Resolve after requires a positive integer');
+ }
- if (timesUntilResolve <= 0) {
- throw new Error('Resolve after requires a positive integer');
- }
+ const promise: Promise<void> = new Promise((resolvePromise) => {
+ counter = () => {
+ if (++currentValue === timesUntilResolve) {
+ resolvePromise();
+ }
+ };
+ });
- const promise: Promise<void> = new Promise((resolvePromise) => {
-
- counter = () => {
-
- if (++currentValue === timesUntilResolve) {
- resolvePromise();
- }
- };
- });
-
- return {
- counter,
- promise
- };
+ return {
+ counter,
+ promise
+ };
};