Skip to content

Commit

Permalink
Reflect review
Browse files Browse the repository at this point in the history
  • Loading branch information
SieR-VR committed Sep 26, 2022
1 parent 952194d commit 1949473
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type ListFactoryFunc<T, K extends keyof T, U = T> = keyof T extends K
: (count: number, item: RecPartial<T> & Omit<T, K>) => Promise<U[]>;

function isPromise<T>(t: T | Promise<T>): t is Promise<T> {
return typeof (t as any)["then"] === "function";
return !!t && typeof (t as any)["then"] === "function";
}

export function lift<T>(t: T | Promise<T>): Promise<T> {
Expand Down Expand Up @@ -272,14 +272,13 @@ async function buildBase<T, K extends keyof T>(
seqNum: number,
builder: Builder<T, K> | Promise<Builder<T, K>>
): Promise<BaseBuild<T>> {
if (isPromise(builder))
builder = await builder;
const resolvedBuilder = await lift(builder);

const t: { [key: string]: any } = {};
const keys = Object.getOwnPropertyNames(builder);
const keys = Object.getOwnPropertyNames(resolvedBuilder);
const derived: BaseDerived[] = [];
for (const key of keys) {
const v = (builder as any)[key];
const v = (resolvedBuilder as any)[key];
let value = v;
if (!!v && typeof v === "object") {
if (isPromise(v)) {
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export class Pipeline<P extends Record<string, unknown> = {}> implements Promise
}

toFactory(): Async.Factory<P> {
return Async.makeFactory(this.current as Promise<Async.Builder<P, keyof P>>);
return Async.makeFactory(this.current as Promise<Async.Builder<P>>);
}
}

0 comments on commit 1949473

Please sign in to comment.