diff --git a/readme.md b/readme.md index 9f99ec2..eba6aec 100644 --- a/readme.md +++ b/readme.md @@ -66,3 +66,20 @@ function get_data_from_slow_source() : string { const get_data_cached = memo_simple(30_000, get_data_from_slow_source); ``` + +### Full async example + +```ts +import { memo_async } from '@js/memo'; + +async function get_data_from_slow_source(name: string) : Promise { + // .... +} + +const get_data_cached = memo_async({ + func: get_data_from_slow_source, + ttl: 30_000, + stale_ttl: 5_000, + promise_ttl: 5_000, +}); +``` diff --git a/src/async.ts b/src/async.ts index 927b2df..d67df9c 100644 --- a/src/async.ts +++ b/src/async.ts @@ -75,7 +75,7 @@ export interface MemoAsyncStoredResult { timer: ReturnType; } -export function memo(opts: MemoAsyncOptions) : T { +export function memo_async(opts: MemoAsyncOptions) : T { const get_key = opts.key ?? default_key; const storage: Record> = Object.create(null); const refreshing: Record> = Object.create(null);