Skip to content

Commit f3a3361

Browse files
committed
store: Call connection.close in PerAccountStore.dispose
This seems hygienic. It makes sense to explicitly clean up HTTP client resources when we know we'll be setting up a new client instance to replace the old one. (The dead-queue reload is currently the only path where PerAccountStore.dispose 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 "TODO abort long-poll and close ApiConnection" 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 7aff4d1 commit f3a3361

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/model/store.dart

Lines changed: 6 additions & 1 deletion
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
}
@@ -980,7 +981,11 @@ class UpdateMachine {
980981
///
981982
/// After this is called, the instance is not in a usable state
982983
/// and should be abandoned.
983-
void dispose() { // TODO abort long-poll and close ApiConnection
984+
///
985+
/// To abort polling mid-request, [store]'s [PerAccountStore.connection]
986+
/// needs to be closed using [ApiConnection.close], which causes in-progress
987+
/// requests to error. [PerAccountStore.dispose] does that.
988+
void dispose() {
984989
assert(!_disposed);
985990
NotificationService.instance.token.removeListener(_registerNotificationToken);
986991
_disposed = true;

0 commit comments

Comments
 (0)