Skip to content

Commit 18ad858

Browse files
Update realtime_mixin.dart.twig
1 parent bba375a commit 18ad858

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

templates/flutter/lib/src/realtime_mixin.dart.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mixin RealtimeMixin {
2525
Map<int, RealtimeSubscription> _subscriptions = {};
2626
bool _notifyDone = true;
2727
StreamSubscription? _websocketSubscription;
28+
bool _creatingSocket = false;
2829

2930
Future<dynamic> _closeConnection() async {
3031
await _websocketSubscription?.cancel();
@@ -33,12 +34,15 @@ mixin RealtimeMixin {
3334
}
3435

3536
_createSocket() async {
37+
if(_creatingSocket) return;
38+
_creatingSocket = true;
3639
final uri = _prepareUri();
3740
if (_websok == null) {
3841
_websok = await getWebSocket(uri);
3942
_lastUrl = uri.toString();
4043
} else {
4144
if (_lastUrl == uri.toString() && _websok?.closeCode == null) {
45+
_creatingSocket = false;
4246
return;
4347
}
4448
_notifyDone = false;
@@ -107,6 +111,8 @@ mixin RealtimeMixin {
107111
throw {{spec.title | caseUcfirst}}Exception(e.message);
108112
}
109113
throw {{spec.title | caseUcfirst}}Exception(e.toString());
114+
} finally {
115+
_creatingSocket = false;
110116
}
111117
}
112118

0 commit comments

Comments
 (0)