Skip to content

Commit

Permalink
Demonstrate a bug when using isolates not in the main isolate
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Oct 1, 2024
1 parent 0bf27dc commit 555e710
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 555e710

Please sign in to comment.