sindresorhus / p-memoize

Memoize promise-returning & async functions
MIT License
396 stars 30 forks source link

Export "in-flight only memoizer" #53

Open fregante opened 1 year ago

fregante commented 1 year ago

I don't know what this means:

pMemoize(fn, {cache: false})

I have to document it every time:

pMemoize(fn, {cache: false /* only while pending */})

The module can export a more readable helper instead:

export const pMemoizePending = (fn, opts) => pMemoize(fn, {...opts, cache: false})

Note: the types of opts should exclude cache

Some tags could also be added to package.json

sindresorhus commented 1 year ago

I would prefer to fix main signature. Maybe a new option instead of setting cache to false? The problem with exporting a separate method is that we have to explain it doesn't have a cache setting and also need to add yet another method for a decorator version.

@Richienb Any thoughts on this?

fregante commented 1 year ago

I don't think that's a big ask. The documentation would look like

memInFlight(fn, options)

Like mem, but just while pending. The options are the same except you can't pass a custom cache.


Same for the decorator. I do agree it's not optimal but… in the code it still reads better than any option could, IMHO

Richienb commented 1 year ago

Maybe a new option instead of setting cache to false?

cache: pending?

fregante commented 1 year ago

I think cache: 'while-pending' is clear enough. "Pending" alone doesn't give enough information and still requires a comment

sindresorhus commented 1 year ago

Let's go with cache: 'while-pending'.