summaryrefslogtreecommitdiff
path: root/js/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/util.ts')
-rw-r--r--js/util.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/js/util.ts b/js/util.ts
index bfde01908..de6a078bb 100644
--- a/js/util.ts
+++ b/js/util.ts
@@ -101,3 +101,29 @@ export function containsOnlyASCII(str: string): boolean {
}
return /^[\x00-\x7F]*$/.test(str);
}
+
+// @internal
+export interface Deferred {
+ promise: Promise<void>;
+ resolve: Function;
+ reject: Function;
+}
+
+/**
+ * Create a wrapper around a promise that could be
+ * resolved externally.
+ * @internal
+ */
+export function deferred(): Deferred {
+ let resolve: Function | undefined;
+ let reject: Function | undefined;
+ const promise = new Promise<void>((res, rej) => {
+ resolve = res;
+ reject = rej;
+ });
+ return {
+ promise,
+ resolve: resolve!,
+ reject: reject!
+ };
+}