Open jackgeek opened 1 year ago
@jackgeek Technically there's no bug, thing is that values are memoized after async function resolves, and it's at resolution point where max
option is evaluated.
See
memoizedAsync(1); // cache size still 0
memoizedAsync(2); // cache size still 0
memoizedAsync(3); // cache size still 0
memoizedAsync(4); // cache size still 0
vs
await memoizedAsync(1); // cache size 1
await memoizedAsync(2); // cache size 2
await memoizedAsync(3); // cache size 3
await memoizedAsync(4); // cache size 4
Still, I agree that desired would be to handle the cache limit at the invocation moment and not at the function resolution moment. I've updated the v1.0 draft proposal to take that into account
When using promise: true option the max option is no longer honored.
See example here: https://codesandbox.io/s/green-sun-fkotwo?file=/src/App.tsx