AsyncExtensions
AsyncExtensions copied to clipboard
Fix race condition in `AsyncCurrentValueSubject`
Description
If a value is sent to the subject while handleNewConsumer() is running, it is possible for the new consumer to miss this value. This is because the currentValue is read before the state is updated with the channel. This is addressed by setting the current value at the same point that the channel is added to the state.
Checklist
- [x] this PR is based on the main branch and is up-to-date, if not please rebase your branch on the top of main
- [x] the commits inside this PR have explicit commit messages
- [ ] unit tests cover the new feature or the bug fix
- [x] the feature is documented in the README.md if it makes sense
- [ ] the CHANGELOG is up-to-date
Hello! I encountered a similar problem. This fix seems to help me. Is there a plan to merge? Thanks anyway!