use compute for background json parsing

This commit is contained in:
fuwa
2019-07-26 21:56:14 +08:00
parent d9c21ec96a
commit 480cafd99f
2 changed files with 7 additions and 2 deletions
+4 -1
View File
@@ -58,6 +58,8 @@ Future<http.Response> rpcHTTP(String method) async {
}
}
dynamic jsonDecode(String responseBody) => json.decode(responseBody);
Future<dynamic> rpc(String method, {String field}) async {
final response = await rpcHTTP(method);
@@ -66,7 +68,8 @@ Future<dynamic> rpc(String method, {String field}) async {
if (response.statusCode != 200) {
return null;
} else {
final _result = json.decode(response.body)['result'];
final _body = await compute(jsonDecode, response.body);
final _result = _body['result'];
final _field = field == null ? _result : _result[field];
return _field;
+3 -1
View File
@@ -44,6 +44,8 @@ Future<http.Response> rpc2(String method) async {
}
}
dynamic jsonDecode(String responseBody) => json.decode(responseBody);
Future<String> rpc2String(String method, {String field}) async {
final response = await rpc2(method);
@@ -52,7 +54,7 @@ Future<String> rpc2String(String method, {String field}) async {
if (response.statusCode != 200) {
return '';
} else {
final _body= json.decode(response.body);
final _body = await compute(jsonDecode, response.body);
final _field = field == null ? _body: _body[field];
return pretty(_field);