From 284f32fc0aa6d6aa513961d53dfc091cd09580c2 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 2 May 2024 15:15:12 -0300 Subject: sugar: promiseWithResolvers --- src/util/sugar.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/util') 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 -- cgit 1.3.0-6-gf8a5