Skip to content

Commit

Permalink
feat: allow initilize/dispose multiple times for same IrisMethodChann…
Browse files Browse the repository at this point in the history
…el object
  • Loading branch information
littleGnAl committed Mar 16, 2023
1 parent 95b2178 commit 00d1388
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/src/iris_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ class IrisMethodChannel {
IrisMethodChannel();

bool _initilized = false;
late final _Messenger messenger;
late final StreamSubscription evntSubscription;
late _Messenger messenger;
late StreamSubscription evntSubscription;
@visibleForTesting
final ScopedObjects scopedEventHandlers = ScopedObjects();
late final int _nativeHandle;
late int _nativeHandle;

@visibleForTesting
late final Isolate workerIsolate;
late final _HotRestartFinalizer _hotRestartFinalizer;
late Isolate workerIsolate;
late _HotRestartFinalizer _hotRestartFinalizer;

static Future<void> _execute(_InitilizationArgs args) async {
SendPort mainApiCallSendPort = args.apiCallPortSendPort;
Expand Down
29 changes: 29 additions & 0 deletions test/iris_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,35 @@ void main() {
_FakeNativeBindingDelegateProvider(nativeBindingDelegate, irisEvent);
});

test(
'able to initilize/dispose multiple times for same IrisMethodChannel object',
() async {
final irisMethodChannel = IrisMethodChannel();
await irisMethodChannel.initilize(nativeBindingsProvider);
final callApiResult1 = await irisMethodChannel
.invokeMethod(const IrisMethodCall('a_func_name', 'params'));
expect(callApiResult1.irisReturnCode, 0);
expect(callApiResult1.data, {});

final callRecord1 = messenger.callApiRecords
.where((e) => e.methodCall.funcName == 'a_func_name');
expect(callRecord1.length, 1);

await irisMethodChannel.dispose();

await irisMethodChannel.initilize(nativeBindingsProvider);
final callApiResult2 = await irisMethodChannel
.invokeMethod(const IrisMethodCall('a_func_name2', 'params'));
expect(callApiResult2.irisReturnCode, 0);
expect(callApiResult2.data, {});

final callRecord2 = messenger.callApiRecords
.where((e) => e.methodCall.funcName == 'a_func_name2');
expect(callRecord2.length, 1);

await irisMethodChannel.dispose();
});

test('invokeMethod', () async {
final irisMethodChannel = IrisMethodChannel();
await irisMethodChannel.initilize(nativeBindingsProvider);
Expand Down

0 comments on commit 00d1388

Please sign in to comment.