Skip to content

Commit fd3fe81

Browse files
committed
store: Call connection.close in PerAccountStore.dispose
This seems hygienic. It makes sense to explicitly clean up an old HTTP client's resources when we've set up a new one, for the dead-queue reload. (The dead-queue reload is currently the only path where this dispose method is called.) It will also make sense to clean up these resources when an account is logged out. That's a feature we'll be implementing soon, with PerAccountStore.dispose in that new path as well. The "abort long-poll and close ApiConnection" TODO was on UpdateMachine's dispose method, not PerAccountStore's. But since PerAccountStore is what owns the connection, its dispose method seemed like the more appropriate place to close the connection.
1 parent 93d683c commit fd3fe81

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/model/store.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
464464
_messages.dispose();
465465
typingStatus.dispose();
466466
updateMachine?.dispose();
467+
connection.close();
467468
_disposed = true;
468469
super.dispose();
469470
}
@@ -978,7 +979,11 @@ class UpdateMachine {
978979
///
979980
/// After this is called, the instance is not in a usable state
980981
/// and should be abandoned.
981-
void dispose() { // TODO abort long-poll and close ApiConnection
982+
///
983+
/// To abort polling mid-request, [store]'s [PerAccountStore.connection]
984+
/// needs to be closed using [ApiConnection.close], which causes in-progress
985+
/// requests to error. [PerAccountStore.dispose] does that.
986+
void dispose() {
982987
assert(!_disposed);
983988
NotificationService.instance.token.removeListener(_registerNotificationToken);
984989
_disposed = true;

0 commit comments

Comments
 (0)