mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
Implement closeRead/closeWrite using TcpStream::shutdown (#903)
This commit is contained in:
parent
6c42ded097
commit
941e27d8c1
6 changed files with 217 additions and 7 deletions
26
js/util.ts
26
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!
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue