Reland isolate platform channels with conditional compilation (#111712)

This commit is contained in:
gaaclarke
2022-09-19 09:52:33 -07:00
committed by GitHub
parent cb8c72545c
commit a7166e7a4e
10 changed files with 217 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:isolate';
import 'package:flutter/services.dart';
@@ -78,6 +79,41 @@ Future<TestStepResult> basicStandardHandshake(dynamic message) async {
'Standard >${toString(message)}<', channel, message);
}
Future<void> _basicBackgroundStandardEchoMain(List<Object> args) async {
final SendPort sendPort = args[2] as SendPort;
final Object message = args[1];
final String name = 'Background Echo >${toString(message)}<';
const String description =
'Uses a platform channel from a background isolate.';
try {
BackgroundIsolateBinaryMessenger.ensureInitialized(
args[0] as RootIsolateToken);
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
'std-echo',
ExtendedStandardMessageCodec(),
);
final Object response = await channel.send(message) as Object;
final TestStatus testStatus = TestStepResult.deepEquals(message, response)
? TestStatus.ok
: TestStatus.failed;
sendPort.send(TestStepResult(name, description, testStatus));
} catch (ex) {
sendPort.send(TestStepResult(name, description, TestStatus.failed,
error: ex.toString()));
}
}
Future<TestStepResult> basicBackgroundStandardEcho(Object message) async {
final ReceivePort receivePort = ReceivePort();
Isolate.spawn(_basicBackgroundStandardEchoMain, <Object>[
ServicesBinding.rootIsolateToken!,
message,
receivePort.sendPort,
]);
return await receivePort.first as TestStepResult;
}
Future<TestStepResult> basicBinaryMessageToUnknownChannel() async {
const BasicMessageChannel<ByteData?> channel =
BasicMessageChannel<ByteData?>(

View File

@@ -90,6 +90,8 @@ class TestStepResult {
],
);
}
static bool deepEquals(dynamic a, dynamic b) => _deepEquals(a, b);
}
Future<TestStepResult> resultOfHandshake(