1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 06:09:25 -05:00

Drop unnecessary Object.assign from createResolvable() (#3548)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2019-12-24 18:59:46 -08:00 committed by Ry Dahl
parent 3bb15ceaea
commit 43fb24f4cd

View file

@ -62,10 +62,13 @@ export function arrayToStr(ui8: Uint8Array): string {
* @internal * @internal
*/ */
export interface ResolvableMethods<T> { export type ResolveFunction<T> = (value?: T | PromiseLike<T>) => void;
resolve: (value?: T | PromiseLike<T>) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
reject: (reason?: any) => void; export type RejectFunction = (reason?: any) => void;
export interface ResolvableMethods<T> {
resolve: ResolveFunction<T>;
reject: RejectFunction;
} }
// @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