summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/defer.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/client/debugger/src/utils/defer.js')
-rw-r--r--devtools/client/debugger/src/utils/defer.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/utils/defer.js b/devtools/client/debugger/src/utils/defer.js
new file mode 100644
index 0000000000..333068087a
--- /dev/null
+++ b/devtools/client/debugger/src/utils/defer.js
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+// @flow
+
+type Deferred<T> = {
+ promise: Promise<T>,
+ resolve: (arg: T) => mixed,
+ reject: (arg: mixed) => mixed,
+};
+
+export default function defer<T>(): Deferred<T> {
+ let resolve = () => {};
+ let reject = () => {};
+ const promise = new Promise((_res, _rej) => {
+ resolve = _res;
+ reject = _rej;
+ });
+
+ return { resolve, reject, promise };
+}