executeStream<S> method

  1. @protected
Stream<S> executeStream<S>(
  1. FlutterRustBridgeTask<S> task
)
inherited

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

Implementation

@protected
Stream<S> executeStream<S>(FlutterRustBridgeTask<S> 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);
    } on _CloseStreamException {
      receivePort.close();
      break;
    }
  }
}