subscribe method

  1. @override
Future<SubscriptionResponse> subscribe(
  1. String method,
  2. List params, {
  3. FutureOr<void> onCancel(
    1. String subscription
    )?,
})
override

Send arbitrary message to RPC node

Implementation

@override
Future<SubscriptionResponse> subscribe(String method, List<dynamic> params,
    {FutureOr<void> Function(String subscription)? onCancel}) async {
  final result = await send(method, params);

  if (result.error != null) {
    throw Exception(result.error.toString());
  }

  final subscription = result.result as String;
  final controller = getOrCreateSubscriptionController(subscription);
  return SubscriptionResponse(
    id: subscription,
    stream: controller.stream,
  );
}