summaryrefslogtreecommitdiff
path: root/js/util.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-10-05 09:16:24 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-10-05 12:16:23 -0400
commit941e27d8c1c2748e62972510f8059838fdc84dad (patch)
tree831a8b52f35c2a25db8f2ccb19d922747be4f31d /js/util.ts
parent6c42ded0970826aaf424f3ae572cb35a4ff212dc (diff)
Implement closeRead/closeWrite using TcpStream::shutdown (#903)
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!
+ };
+}