From 01bafc7d0a1f69ef5245f2612ff65d0f20bc2f15 Mon Sep 17 00:00:00 2001 From: Littlegnal <8847263+littleGnAl@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:44:55 +0000 Subject: [PATCH] fix: Wait for the executor.dispose before exit the isolate --- .../platform/io/iris_method_channel_internal_io.dart | 10 ++++++---- test/iris_method_channel_test.dart | 4 ---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/src/platform/io/iris_method_channel_internal_io.dart b/lib/src/platform/io/iris_method_channel_internal_io.dart index 72b07b8..9134d6b 100644 --- a/lib/src/platform/io/iris_method_channel_internal_io.dart +++ b/lib/src/platform/io/iris_method_channel_internal_io.dart @@ -49,7 +49,9 @@ class _Messenger implements DisposableObject { } _isDisposed = true; requestPort.send(null); - await responseQueue.cancel(); + // Wait for `executor.dispose` done in isolate. + await responseQueue.next; + responseQueue.cancel(); } } @@ -450,8 +452,9 @@ class IrisMethodChannelInternalIO implements IrisMethodChannelInternal { // Wait for messages from the main isolate. await for (final request in apiCallPort) { if (request == null) { - // Exit if the main isolate sends a null message, indicating there are no - // more files to read and parse. + executor.dispose(); + mainApiCallSendPort.send(null); + // Ready exit the isolate. break; } @@ -494,7 +497,6 @@ class IrisMethodChannelInternalIO implements IrisMethodChannelInternal { } } - executor.dispose(); Isolate.exit(onExitSendPort, 0); } diff --git a/test/iris_method_channel_test.dart b/test/iris_method_channel_test.dart index 4752c19..5a5d0d8 100644 --- a/test/iris_method_channel_test.dart +++ b/test/iris_method_channel_test.dart @@ -209,8 +209,6 @@ void main() { test('disposed', () async { await irisMethodChannel.initilize([]); await irisMethodChannel.dispose(); - // Wait for `dispose` completed. - await Future.delayed(const Duration(milliseconds: 500)); final callRecord1 = messenger.callApiRecords .where((e) => e.methodCall.funcName == 'destroyNativeApiEngine'); expect(callRecord1.length, 1); @@ -227,8 +225,6 @@ void main() { await irisMethodChannel.initilize([]); await irisMethodChannel.dispose(); await irisMethodChannel.dispose(); - // Wait for `dispose` completed. - await Future.delayed(const Duration(milliseconds: 500)); final callRecord1 = messenger.callApiRecords .where((e) => e.methodCall.funcName == 'destroyNativeApiEngine'); expect(callRecord1.length, 1);