executeStream<S, E extends Object> method

  1. @protected
Stream<S> executeStream<S, E extends Object>(
  1. FlutterRustBridgeTask<S, E> task
)
inherited

Similar to executeNormal, except that this will return a Stream instead of a Future.

Implementation

@protected
Stream<S> executeStream<S, E extends Object>(
    FlutterRustBridgeTask<S, E> task) async* {
  final func = task.constMeta.debugName;
  final nextIndex = _streamSinkNameIndex.update(func, (value) => value + 1,
      ifAbsent: () => 0);
  final name = '__frb_streamsink_${func}_$nextIndex';
  final receivePort = broadcastPort(name);
  task.callFfi(receivePort.sendPort.nativePort);

  await for (final raw in receivePort) {
    try {
      yield _transformRust2DartMessage(raw, task.parseSuccessData,
          task.parseErrorData, wire2apiPanicError);
    } on _CloseStreamException {
      receivePort.close();
      break;
    }
  }
}