diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/sugar.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js index 183a75d5..1c057ed1 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -266,6 +266,16 @@ export function delay(ms) { return new Promise((res) => setTimeout(res, ms)); } +export function promiseWithResolvers() { + let obj = {}; + + obj.promise = + new Promise((...opts) => + ([obj.resolve, obj.reject] = opts)); + + return obj; +} + // Stolen from here: https://stackoverflow.com/a/3561711 // // There's a proposal for a native JS function like this, 8ut it's not even |