invokeMethod method

dynamic invokeMethod(
  1. String method,
  2. Map params
)

Implementation

dynamic invokeMethod(String method, Map params) {
  final id = UuidV4().generate();
  hostSendPort?.send(json.encode({
    "cmd": "invokeMethod",
    "id": id,
    "method": method,
    "params": params,
  }));
  final file = File("$_tempPath/data_$id");
  dynamic content;
  var retryCount = 0;
  while (true) {
    if (retryCount > 2000) {
      throw Error.safeToString("未连接到调试宿主");
    }
    if (file.existsSync()) {
      final fileContent = file.readAsStringSync();
      if (!fileContent.isEmpty) {
        content = json.decode(fileContent);
        file.delete();
        break;
      }
    }
    final delayTime = 5;
    retryCount += delayTime;
    sleep(Duration(milliseconds: delayTime));
  }
  return content;
}