Skip to content

Commit

Permalink
Eagerly free resources on CupertinoClient.close() (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan authored May 2, 2024
1 parent ec73b19 commit dd31e64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

* Upgrade to `package:ffigen` 11.0.0.
* Bring `WebSocket` behavior in line with the documentation by throwing
`WebSocketConnectionClosed` rather `StateError` when attempting to send
`WebSocketConnectionClosed` rather than `StateError` when attempting to send
data to or close an already closed `CupertinoWebSocket`.
* Update minimum supported iOS/macOS versions to be in sync with the minimum
(best effort) supported for Flutter: iOS 12, macOS 10.14
(best effort) supported for Flutter: iOS 12, macOS 10.14.
* Eagerly free resources on `CupertinoClient.close()`.

## 1.4.0

Expand Down
8 changes: 8 additions & 0 deletions pkgs/cupertino_http/lib/src/cupertino_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1613,4 +1613,12 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
onWebSocketTaskClosed: _onWebSocketTaskClosed);
return task;
}

/// Free resources related to this session after the last task completes.
/// Returns immediately.
///
/// See [NSURLSession finishTasksAndInvalidate](https://developer.apple.com/documentation/foundation/nsurlsession/1407428-finishtasksandinvalidate)
void finishTasksAndInvalidate() {
_nsObject.finishTasksAndInvalidate();
}
}
1 change: 1 addition & 0 deletions pkgs/cupertino_http/lib/src/cupertino_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class CupertinoClient extends BaseClient {

@override
void close() {
_urlSession?.finishTasksAndInvalidate();
_urlSession = null;
}

Expand Down

0 comments on commit dd31e64

Please sign in to comment.