handleStream method

  1. @preferInline
  2. @internal
void handleStream(
  1. Stream<T> create(), {
  2. required bool didChangeDependency,
})
inherited

Listens to a Stream and convert it into an AsyncValue.

Implementation

@preferInline
@internal
void handleStream(
  Stream<T> Function() create, {
  required bool didChangeDependency,
}) {
  _handleAsync(didChangeDependency: didChangeDependency, ({
    required data,
    required done,
    required error,
    required last,
  }) {
    final rawStream = create();
    final stream = rawStream.isBroadcast
        ? rawStream
        : rawStream.asBroadcastStream(onCancel: (sub) => sub.cancel());

    stream.lastCancelable(last, orElseError: _missingLastValueError);

    final sub = stream.listen(data, onError: error, onDone: done);
    return sub.cancel;
  });
}