You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like for AsyncCache, not remembering an error is only meaningful if one expects the next call to behave differently. Which only the creator of the function can know.
So it would make sense to have a flag to control whether errors should be remembered.
But it's not an error to do so.
Having looked at the code, I'm not sure changing the behavior of AsyncMemoizer is a good idea.
Or at least not doing it the most obvious way.
The way it's implemented today, a call to runOnce will immediately complete the Completer with the future returned by the function, long before that future completes.
If someone calles runOnce again, they immediately get the result future and isn't run a second time.
If the function then completes with an error later, only then is the completer fully completed.
Which means that "retrying on error" would still give the error to a number of callers, and if we want to clear the cache after that, we need to create a new Completer, because the old one is spent.
We can't just wait for the function's future to complete, to check if it's with an error, because then further calls to runOnce in the meantime will try to run function a second time.
So, at least for AsyncMemoizer, I think the best choice is to not change it, and maybe just document extra clearly that when you call runOnce, you get the result of that one run, whatever it is.
Steps to reproduce
To reproduce the same issue you can refer the code sample given below.
Expected results
It should only cache successful result.
Actual results
It should not cache exception.
Code sample
Code sample
The text was updated successfully, but these errors were encountered: