Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate a bug when using isolates not in the main isolate #1622

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Demonstrate a bug when using isolates not in the main isolate
  • Loading branch information
brianquinlan committed Oct 1, 2024
commit 555e71001949fbcb71f11b139c2eb4add7724c3b
24 changes: 24 additions & 0 deletions pkgs/ffigen/test/native_objc_test/protocol_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import 'dart:async';
import 'dart:ffi';
import 'dart:isolate';
import 'dart:io';

import 'package:ffi/ffi.dart';
Expand Down Expand Up @@ -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<int>();
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();

Expand Down
Loading