From 555e71001949fbcb71f11b139c2eb4add7724c3b Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 1 Oct 2024 15:57:02 -0700 Subject: [PATCH] Demonstrate a bug when using isolates not in the main isolate --- .../test/native_objc_test/protocol_test.dart | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkgs/ffigen/test/native_objc_test/protocol_test.dart b/pkgs/ffigen/test/native_objc_test/protocol_test.dart index ac62d65b5..b7ee7c815 100644 --- a/pkgs/ffigen/test/native_objc_test/protocol_test.dart +++ b/pkgs/ffigen/test/native_objc_test/protocol_test.dart @@ -7,6 +7,7 @@ import 'dart:async'; import 'dart:ffi'; +import 'dart:isolate'; import 'dart:io'; import 'package:ffi/ffi.dart'; @@ -208,6 +209,29 @@ void main() { expect(await listenerCompleter.future, 123); }); + test('Method implementation as listener - Isolate', () async { + await Isolate.run(() async { + final consumer = ProtocolConsumer.new1(); + + final listenerCompleter = Completer(); + final myProtocol = MyProtocol.implementAsListener( + instanceMethod_withDouble_: (NSString s, double x) { + throw UnimplementedError(); + }, + optionalMethod_: (SomeStruct s) { + throw UnimplementedError(); + }, + voidMethod_: (int x) { + listenerCompleter.complete(x); + }, + ); + consumer.callMethodOnRandomThread_(myProtocol); + // Will fail if you remove the delay. + // await Future.delayed(const Duration(milliseconds: 0)); + await listenerCompleter.future; + }); + }); + test('Multiple protocol implementation as listener', () async { final consumer = ProtocolConsumer.new1();