diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-05-02 00:23:16 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-05-02 00:23:16 +0200 |
| commit | 73973edab9aaa81312ba80a68bfe34bf5abcecd9 (patch) | |
| tree | 9d3916655c416407e12dc66e9f1f865cec0fb2b3 /src/utils/resolve_after.js | |
| parent | 55fb920baa9792266be1a6b981f954c622c1eaf9 (diff) | |
Add pact test for forums store
Diffstat (limited to 'src/utils/resolve_after.js')
| -rw-r--r-- | src/utils/resolve_after.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/resolve_after.js b/src/utils/resolve_after.js new file mode 100644 index 0000000..0884401 --- /dev/null +++ b/src/utils/resolve_after.js @@ -0,0 +1,25 @@ +export const resolveAfter = function (timesUntilResolve) { + + let counter = null; + let currentValue = 0; + + if (typeof timesUntilResolve !== 'number' || timesUntilResolve <= 0) { + throw new Error('Resolve after requires a positive integer'); + } + + const promise = new Promise((resolvePromise) => { + + counter = () => { + + if (++currentValue === timesUntilResolve) { + resolvePromise(); + } + }; + }); + + return { + counter, + promise + }; + +}; |