X-Git-Url: https://git.r.bdr.sh/rbdr/forum/blobdiff_plain/a7cf03c192470cbab13edeb1aec99e0c66dede10..3d65cb04707cf3af11885995fd1110a5971d8b00:/src/lib/utils/resolve_after.ts 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 + counter: () => void; + promise: Promise; }; 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 = new Promise((resolvePromise) => { + counter = () => { + if (++currentValue === timesUntilResolve) { + resolvePromise(); + } + }; + }); - const promise: Promise = new Promise((resolvePromise) => { - - counter = () => { - - if (++currentValue === timesUntilResolve) { - resolvePromise(); - } - }; - }); - - return { - counter, - promise - }; + return { + counter, + promise + }; };