Skip to content

Commit ff85dc1

Browse files
committed
fix realtime refreshing
1 parent 6df01af commit ff85dc1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mixin RealtimeMixin {
2020
late WebSocketFactory getWebSocket;
2121
GetFallbackCookie? getFallbackCookie;
2222

23-
_closeConnection() {
24-
_websok?.sink.close(normalClosure);
23+
Future<dynamic> _closeConnection() async {
24+
return await _websok?.sink.close(normalClosure);
2525
}
2626

2727
_createSocket() async {
@@ -32,7 +32,7 @@ mixin RealtimeMixin {
3232
if (_lastUrl == uri.toString() && _websok?.closeCode == null) {
3333
return;
3434
}
35-
_closeConnection();
35+
await _closeConnection();
3636
_lastUrl = uri.toString();
3737
print('subscription: $_lastUrl');
3838
_websok = await getWebSocket(uri);
@@ -112,7 +112,7 @@ mixin RealtimeMixin {
112112
Future.delayed(Duration.zero, () => _createSocket());
113113
RealtimeSubscription subscription = RealtimeSubscription(
114114
stream: controller.stream,
115-
close: () {
115+
close: () async {
116116
controller.close();
117117
channels.forEach((channel) {
118118
this._channels[channel]!.remove(controller);
@@ -121,9 +121,9 @@ mixin RealtimeMixin {
121121
}
122122
});
123123
if(this._channels.isNotEmpty) {
124-
Future.delayed(Duration.zero, () => _createSocket());
124+
await Future.delayed(Duration.zero, () => _createSocket());
125125
} else {
126-
_closeConnection();
126+
await _closeConnection();
127127
}
128128
});
129129
return subscription;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'realtime_message.dart';
22

33
class RealtimeSubscription {
44
final Stream<RealtimeMessage> stream;
5-
final Function() close;
5+
final Future<void> Function() close;
66

77
RealtimeSubscription({required this.stream, required this.close});
88
}

0 commit comments

Comments
 (0)