-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Disposables management for thread-safe operations #106
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
base: main
Are you sure you want to change the base?
fix: Disposables management for thread-safe operations #106
Conversation
Hello, to make the commit valid, you must rename it with the correct tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Hi, can you provide benchmark results in your PR description for both before and after your change? |
|
||
namespace Chinook.DynamicMvvm | ||
{ | ||
public partial class ViewModelBase | ||
{ | ||
private readonly Dictionary<string, IDisposable> _disposables = new Dictionary<string, IDisposable>(); | ||
private readonly CancellationTokenSource _cts = new CancellationTokenSource(); | ||
private readonly ConcurrentDictionary<string, IDisposable> _disposables = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way the library is currently designed doesn't imply thread safety. If we want to add thread safety as a feature, we would need to do more changes than just this one.
Extension methods such as TryGetDisposable
, GetOrCreateDisposable
, and their calling sites would need to be reworked with thread safety in mind because they currently have a naive implementation. (e.g. Checking if the dictionary contains an item and adding an item based on that condition is done in 2 steps rather than as an atomic operation.)
It makes sense to have thread safety in this library. However if we add it, it would need to be everywhere to be consistent.
GitHub Issue: #105
Proposed Changes
What is the current behavior?
Adding or removing a disposable could result in an InvalidOperationException in a muti threaded context.
What is the new behavior?
Enumerating disposables while adding or removing is now thread-safe.
Impact on version
build
folder was changed..github
folder was changed.Checklist
Please check that your PR fulfills the following requirements:
Other information