Skip to content

Commit

Permalink
Fixed widget properties not updating if multiple subscriptions are sh…
Browse files Browse the repository at this point in the history
…ared in a tab
  • Loading branch information
Gold872 committed Dec 17, 2023
1 parent 57ab14a commit 0da3959
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/services/nt4_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class NT4Subscription {

Object? currentValue;
final List<Function(Object?)> _listeners = [];
bool _newValueRequested = false;
// Multiple instances of this can be used at once, so it has to request the new value for all of the subscription streams
int _newValueRequestCount = 0;

NT4Subscription({
required this.topic,
Expand All @@ -77,10 +78,12 @@ class NT4Subscription {
Object? lastYielded = currentValue;

while (true) {
if (lastYielded != currentValue || yieldAll || _newValueRequested) {
if (lastYielded != currentValue ||
yieldAll ||
_newValueRequestCount > 0) {
yield currentValue;
lastYielded = currentValue;
_newValueRequested = false;
_newValueRequestCount--;
}
await Future.delayed(
Duration(milliseconds: (options.periodicRateSeconds * 1000).round()));
Expand All @@ -95,7 +98,7 @@ class NT4Subscription {
}

void requestNewValue() {
_newValueRequested = true;
_newValueRequestCount = useCount;
}

Map<String, dynamic> _toSubscribeJson() {
Expand Down

0 comments on commit 0da3959

Please sign in to comment.