diff --git a/src/phunk.ts b/src/phunk.ts index e705491..366213e 100644 --- a/src/phunk.ts +++ b/src/phunk.ts @@ -7,7 +7,7 @@ interface Config { const noop = () => {} class Phunk { - #fn: () => T + #fn: () => T | Promise #promise: Promise | null = null @@ -20,7 +20,7 @@ class Phunk { #ttl #lastResolve = 0 - constructor(fn: () => T, config?: Config) { + constructor(fn: () => T | Promise, config?: Config) { const options = config ?? {} if (typeof options.ttl !== 'undefined' && (!Number.isSafeInteger(options.ttl) || options.ttl < 0)) { @@ -59,7 +59,7 @@ class Phunk { if (!this.#isResolving) { this.#promise = this.#resolve() } - return this.#promise + return this.#promise as Promise } async #resolve() {