mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-10-11 20:50:51 -04:00
eliminate race condition with listen/watch
This commit is contained in:
parent
34f9bea6eb
commit
61855521dc
4 changed files with 14 additions and 13 deletions
|
@ -608,14 +608,13 @@ class _DHTLogSpine {
|
|||
Future<void> watch() async {
|
||||
// This will update any existing watches if necessary
|
||||
try {
|
||||
await _spineRecord.watch(subkeys: [ValueSubkeyRange.single(0)]);
|
||||
|
||||
// Update changes to the head record
|
||||
// xxx: check if this localChanges can be false...
|
||||
// xxx: Don't watch for local changes because this class already handles
|
||||
// xxx: notifying listeners and knows when it makes local changes
|
||||
_subscription ??=
|
||||
await _spineRecord.listen(localChanges: true, _onSpineChanged);
|
||||
await _spineRecord.watch(subkeys: [ValueSubkeyRange.single(0)]);
|
||||
} on Exception {
|
||||
// If anything fails, try to cancel the watches
|
||||
await cancelWatch();
|
||||
|
|
|
@ -482,13 +482,13 @@ class _DHTShortArrayHead {
|
|||
Future<void> watch() async {
|
||||
// This will update any existing watches if necessary
|
||||
try {
|
||||
await _headRecord.watch(subkeys: [ValueSubkeyRange.single(0)]);
|
||||
|
||||
// Update changes to the head record
|
||||
// Don't watch for local changes because this class already handles
|
||||
// notifying listeners and knows when it makes local changes
|
||||
_subscription ??=
|
||||
await _headRecord.listen(localChanges: false, _onHeadValueChanged);
|
||||
|
||||
await _headRecord.watch(subkeys: [ValueSubkeyRange.single(0)]);
|
||||
} on Exception {
|
||||
// If anything fails, try to cancel the watches
|
||||
await cancelWatch();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue