Skip to content

Commit b501133

Browse files
authored
⚡ Close CronetEngine when closing the CronetClient (#2422)
Now the `CronetEngine` shall be closed along with the adapter and the client. This reduces the possibility with #2300, learned from dart-lang/http#1136 (comment). This PR cannot be effectively tested due to the unpublic closed state. ### Additional context and info (if any) dart-lang/http#1795
1 parent 9a233d5 commit b501133

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

plugins/native_dio_adapter/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
*None.*
5+
- Close the `CronetEngine` when closing the `CronetClient` by default.
66

77
## 1.4.0
88

plugins/native_dio_adapter/lib/src/cronet_adapter.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import 'conversion_layer_adapter.dart';
88
/// to the native platform by making use of
99
/// [cronet_http](https://pub.dev/packages/cronet_http).
1010
class CronetAdapter implements HttpClientAdapter {
11-
CronetAdapter(CronetEngine? engine)
12-
: _conversionLayer = ConversionLayerAdapter(
11+
CronetAdapter(
12+
CronetEngine? engine, {
13+
bool closeEngine = true,
14+
}) : _conversionLayer = ConversionLayerAdapter(
1315
engine == null
1416
? CronetClient.defaultCronetEngine()
15-
: CronetClient.fromCronetEngine(engine),
17+
: CronetClient.fromCronetEngine(engine, closeEngine: closeEngine),
1618
);
1719

1820
final ConversionLayerAdapter _conversionLayer;

0 commit comments

Comments
 (0)