Skip to content

Commit

Permalink
Switch to Isolate.run
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Oct 4, 2024
1 parent c5619ae commit fb54515
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions pkgs/ffigen/test/native_objc_test/isolate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@ import '../test_utils.dart';
import 'isolate_bindings.dart';
import 'util.dart';

// TODO(https://github.com/dart-lang/coverage/issues/472): Delete this and use
// Isolate.run once the coverage bug is fixed.
Future<R> isolateRun<R>(FutureOr<R> computation()) async {
FutureOr<R> Function()? comp = computation;
Future<void> run(SendPort sendPort) async {
sendPort.send(await comp!());
comp = null;
sendPort.send(null);
Isolate.current.kill();
}

final port = ReceivePort();
final queue = StreamQueue(port);
final isolate = await Isolate.spawn(run, port.sendPort);
final result = await queue.next as R;
await queue.next; // Wait for isolate to release its reference to comp.
port.close();
return result;
}

void main() {
group('isolate', () {
setUpAll(() {
Expand Down Expand Up @@ -98,7 +78,7 @@ void main() {
Sendable? sendable = Sendable.new1();
sendable.value = 123;

final oldValue = await isolateRun(() {
final oldValue = await Isolate.run(() {
final oldValue = sendable!.value;
sendable!.value = 456;
return oldValue;
Expand Down Expand Up @@ -172,7 +152,7 @@ void main() {
final completer = Completer<int>();
ObjCBlock<Void Function(Int32)>? block = makeBlock(completer);

await isolateRun(() {
await Isolate.run(() {
block!(123);
});
final value = await completer.future;
Expand All @@ -193,7 +173,7 @@ void main() {
expect(objectRetainCount(pointer), 1);
expect(sendable.ref.isReleased, isFalse);

final (oldIsReleased, newIsReleased) = await isolateRun(() {
final (oldIsReleased, newIsReleased) = await Isolate.run(() {
final oldIsReleased = sendable.ref.isReleased;
sendable!.ref.release();
return (oldIsReleased, sendable.ref.isReleased);
Expand All @@ -213,7 +193,7 @@ void main() {

expect(sendable.ref.isReleased, isFalse);

await isolateRun(() {
await Isolate.run(() {
sendable!.ref.release();
});

Expand Down

0 comments on commit fb54515

Please sign in to comment.