]> git.r.bdr.sh - rbdr/forum/blob - src/utils/resolve_after.js
Add getForum pact, normalize stores
[rbdr/forum] / src / utils / resolve_after.js
1 export const resolveAfter = function (timesUntilResolve) {
2
3 let counter = null;
4 let currentValue = 0;
5
6 if (typeof timesUntilResolve !== 'number' || timesUntilResolve <= 0) {
7 throw new Error('Resolve after requires a positive integer');
8 }
9
10 const promise = new Promise((resolvePromise) => {
11
12 counter = () => {
13
14 if (++currentValue === timesUntilResolve) {
15 resolvePromise();
16 }
17 };
18 });
19
20 return {
21 counter,
22 promise
23 };
24
25 };