From 2b6eaaed6039d9134fb698ef18195f2e362c3c45 Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Sat, 29 Jul 2023 00:10:59 +0400 Subject: [PATCH] Cancel refresh timer --- lib/src/subscription/client_subscription_impl.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/subscription/client_subscription_impl.dart b/lib/src/subscription/client_subscription_impl.dart index 7d92247..10ca338 100644 --- a/lib/src/subscription/client_subscription_impl.dart +++ b/lib/src/subscription/client_subscription_impl.dart @@ -189,6 +189,8 @@ base mixin CentrifugeClientSubscriptionSubscribeMixin return await ready(); } _setState(CentrifugeSubscriptionState$Subscribing(since: state.since)); + _refreshTimer?.cancel(); + _refreshTimer = null; final subscribed = await _transport.subscribe( channel, _config, @@ -275,6 +277,8 @@ base mixin CentrifugeClientSubscriptionSubscribeMixin @override Future unsubscribe( [int code = 0, String reason = 'unsubscribe called']) async { + _refreshTimer?.cancel(); + _refreshTimer = null; if (state.isUnsubscribed) return; _setState(CentrifugeSubscriptionState.unsubscribed( code: code, @@ -318,7 +322,7 @@ base mixin CentrifugeClientSubscriptionSubscribeMixin _refreshTimer?.cancel(); _refreshTimer = null; final token = await _config.getToken?.call(); - if (token == null) return; + if (token == null || !state.isSubscribed) return; final result = await _transport.sendSubRefresh(channel, token); if (result.expires) _setRefreshTimer(result.ttl); });