mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
move dataHandler and errorHandler up in scope
This commit is contained in:
parent
4c12e870b1
commit
73ecbf15d5
1 changed files with 12 additions and 5 deletions
|
@ -17,10 +17,13 @@ class JsonRPC {
|
|||
final String host;
|
||||
final int port;
|
||||
final Duration connectionTimeout;
|
||||
Socket? socket;
|
||||
|
||||
Socket? socket;
|
||||
StreamSubscription<Uint8List>? _subscription;
|
||||
|
||||
void Function(List<int>)? _onData;
|
||||
void Function(Object, StackTrace)? _onError;
|
||||
|
||||
Future<dynamic> request(String jsonRpcRequest) async {
|
||||
final completer = Completer<dynamic>();
|
||||
final List<int> responseData = [];
|
||||
|
@ -49,6 +52,8 @@ class JsonRPC {
|
|||
}
|
||||
}
|
||||
|
||||
_onData = dataHandler;
|
||||
|
||||
void errorHandler(Object error, StackTrace trace) {
|
||||
Logging.instance
|
||||
.log("JsonRPC errorHandler: $error\n$trace", level: LogLevel.Error);
|
||||
|
@ -61,6 +66,8 @@ class JsonRPC {
|
|||
// TODO do we need to recreate the socket?
|
||||
}
|
||||
|
||||
_onError = errorHandler;
|
||||
|
||||
void doneHandler() {
|
||||
Logging.instance.log(
|
||||
"JsonRPC doneHandler: not destroying socket ${socket?.address}:${socket?.port}",
|
||||
|
@ -78,8 +85,8 @@ class JsonRPC {
|
|||
socket ??= await SecureSocket.connect(host, port,
|
||||
timeout: connectionTimeout, onBadCertificate: (_) => true);
|
||||
_subscription ??= socket!.listen(
|
||||
dataHandler,
|
||||
onError: errorHandler,
|
||||
_onData,
|
||||
onError: _onError,
|
||||
onDone: doneHandler,
|
||||
cancelOnError: true,
|
||||
);
|
||||
|
@ -90,8 +97,8 @@ class JsonRPC {
|
|||
timeout: connectionTimeout,
|
||||
);
|
||||
_subscription ??= socket!.listen(
|
||||
dataHandler,
|
||||
onError: errorHandler,
|
||||
_onData,
|
||||
onError: _onError,
|
||||
onDone: doneHandler,
|
||||
cancelOnError: true,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue