Skip to content
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

Recommended handling in ConcurrencyDictionary<string, Task<T>> when task fails #62

Open
passuied opened this issue Mar 13, 2020 · 2 comments

Comments

@passuied
Copy link

passuied commented Mar 13, 2020

Hi @davidfowl,

Trying to get rid of Task.Result in our code and follow your approach in AsyncGuidance.md#concurrentdictionarygetoradd by storing the Task instead of the actual value.
In our tests, it causes issue when the task fails (e.g. HTTP Exception) but the task obviously still gets added to the cache...

Any recommendations here?

Thanks,
Patrick

@davidfowl
Copy link
Owner

@passuied Just saw this. This is a tricky one. If you want to remove the entry from the dictionary when it fails then you might need something like GetOrAddAsync (https://gist.github.com/davidfowl/3dac8f7b3d141ae87abf770d5781feed#file-concurrentdictionaryextensions-cs-L53).

@bartelink
Copy link

Another approach might be to wrap it like this: https://stackoverflow.com/a/33942013/11635
There's an evolution of that with expiration semantics too (there are some tests if one wanted to port it to C#)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants