aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util.js')
-rw-r--r--src/lib/util.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lib/util.js b/src/lib/util.js
index 6de07e5..a4e0025 100644
--- a/src/lib/util.js
+++ b/src/lib/util.js
@@ -5,5 +5,26 @@ module.exports = {
isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n)
+ },
+
+ /**
+ * Creates a Promise that can be resolved or rejected from the outside
+ *
+ * @param {Function} abortCallback
+ * @return {Promise}
+ */
+ createCallablePromise(abortCallback = null) {
+ let promise, resolve, reject
+ promise = new Promise(function(_resolve, _reject) {
+ resolve = _resolve
+ reject = _reject
+ })
+ promise.resolve = function(result) {
+ resolve(result)
+ }
+ promise.reject = function(result) {
+ reject(result)
+ }
+ return promise
}
-} \ No newline at end of file
+}