-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache maxAge is evaluated wrong for async functions #81
Comments
|
I understand that the function returns And since p-memoize is build on top of mem the same unexpected behaviour occours there too. |
No, Promises are objects that are returned immediately.
I didn't say that it works there, but that it can be asked/reported there as it would be more appropriate |
Okay. Then the mention in doc about I was asking about this, because in JS |
I've noticed, that when memoizing long lasting async functions, the
maxAge
is evaluated relative to the moment when function call started. But in case of sync functions it is evaluated relative to the moment the function was resolved.Expected: Sync functions as is. Async functions (functions that return promise)
maxAge
should be evaluated relative to when promise is resolved.Current: Async functions
maxAge
is evaluated relative to the moment when Promise is returned. (Not resolved, as I would expect!)Fix: Dirty fix is add
await
, but then all memoized function will be async. Clean fix is to change beaviour base on function return type. If Promise then wait till it's resolved. Else as is now.I really appriciate your work, it's great library, just I can't use it because of this unexpected behaviour. Or if I miss understood something and it's working correctly I'm in advance sorry.
The text was updated successfully, but these errors were encountered: