Fixed unhandled exception in `withZoneArena` (#108)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea60851..041d345 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 1.1.2
+
+Fixed unhandled exception in `withZoneArena` (#107).
+
## 1.1.1
Adds a sanity check to `Pointer<Utf8>` and `Pointer<Utf16>` extension methods
diff --git a/lib/src/arena.dart b/lib/src/arena.dart
index 1fdd1d2..87a13d6 100644
--- a/lib/src/arena.dart
+++ b/lib/src/arena.dart
@@ -150,7 +150,9 @@
final result = computation();
if (result is Future) {
isAsync = true;
- result.whenComplete(arena.releaseAll);
+ return result.whenComplete(() {
+ arena.releaseAll();
+ }) as R;
}
return result;
}, zoneValues: {#_arena: arenaHolder});
diff --git a/pubspec.yaml b/pubspec.yaml
index 89e6180..46c3750 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: ffi
-version: 1.1.1
+version: 1.1.2
homepage: https://github.com/dart-lang/ffi
description: Utilities for working with Foreign Function Interface (FFI) code.
diff --git a/test/arena_test.dart b/test/arena_test.dart
index 3af0bb5..51cb9bf 100644
--- a/test/arena_test.dart
+++ b/test/arena_test.dart
@@ -163,6 +163,30 @@
expect(freed.single, 1234);
});
+ test('zone future error', () async {
+ bool caughtError = false;
+ bool uncaughtError = false;
+
+ Future<int> asyncFunction() async {
+ throw Exception('Exception 4');
+ }
+
+ final future = runZonedGuarded(() {
+ return withZoneArena(asyncFunction).catchError((error) {
+ caughtError = true;
+ return 5;
+ });
+ }, (error, stackTrace) {
+ uncaughtError = true;
+ });
+
+ final result = (await Future.wait([future!])).single;
+
+ expect(result, 5);
+ expect(caughtError, true);
+ expect(uncaughtError, false);
+ });
+
test('allocate during releaseAll', () {
final countingAllocator = CountingAllocator();
final arena = Arena(countingAllocator);