Skip to content

Commit

Permalink
Instead of Promise<Promise<T>>, return Promise<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
joliss authored and borisdiakur committed Mar 1, 2024
1 parent 2990ee2 commit 91a3f84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ export default function buildMemoizer(
fn: <FN extends (...args: never) => unknown>(
fn: FN,
opt?: Partial<MemoizerOptions>
) => Promise<(...args: Parameters<FN>) => Promise<ReturnType<FN>>>
) => Promise<(...args: Parameters<FN>) => EnsurePromise<ReturnType<FN>>>
getCacheFilePath: (
fn: (...args: never) => unknown,
args: unknown[],
opt: Partial<MemoizerOptions>
) => string
invalidate: (cacheId?: string) => Promise<void>
}

type EnsurePromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;
```

## Options
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ export default function buildMemoizer(
await initCache(memoizerOptions.cachePath || '')
return memoizeFn(fn as never, opt) as unknown as (
...args: Parameters<FN>
) => Promise<ReturnType<FN>>
) => EnsurePromise<ReturnType<FN>>
},
getCacheFilePath: getCacheFilePathBound,
invalidate: invalidateCache,
}
}

type EnsurePromise<T> = T extends PromiseLike<unknown> ? T : Promise<T>;

0 comments on commit 91a3f84

Please sign in to comment.