mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
Drop unnecessary Object.assign from createResolvable() (#3548)
This commit is contained in:
parent
3bb15ceaea
commit
43fb24f4cd
1 changed files with 15 additions and 10 deletions
|
@ -62,10 +62,13 @@ export function arrayToStr(ui8: Uint8Array): string {
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export type ResolveFunction<T> = (value?: T | PromiseLike<T>) => void;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
export type RejectFunction = (reason?: any) => void;
|
||||||
|
|
||||||
export interface ResolvableMethods<T> {
|
export interface ResolvableMethods<T> {
|
||||||
resolve: (value?: T | PromiseLike<T>) => void;
|
resolve: ResolveFunction<T>;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
reject: RejectFunction;
|
||||||
reject: (reason?: any) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
|
@ -73,13 +76,15 @@ export type Resolvable<T> = Promise<T> & ResolvableMethods<T>;
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export function createResolvable<T>(): Resolvable<T> {
|
export function createResolvable<T>(): Resolvable<T> {
|
||||||
let methods: ResolvableMethods<T>;
|
let resolve: ResolveFunction<T>;
|
||||||
const promise = new Promise<T>((resolve, reject): void => {
|
let reject: RejectFunction;
|
||||||
methods = { resolve, reject };
|
const promise = new Promise<T>((res, rej): void => {
|
||||||
});
|
resolve = res;
|
||||||
// TypeScript doesn't know that the Promise callback occurs synchronously
|
reject = rej;
|
||||||
// therefore use of not null assertion (`!`)
|
}) as Resolvable<T>;
|
||||||
return Object.assign(promise, methods!) as Resolvable<T>;
|
promise.resolve = resolve!;
|
||||||
|
promise.reject = reject!;
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
|
|
Loading…
Add table
Reference in a new issue