subscribe method

  1. @override
FutureOr<void> subscribe(
  1. void emit(
    1. AsyncState<T> state
    )
)
override

Starts listening to the stream and emits appropriate states.

Emits AsyncLoading initially, then AsyncSuccess for each stream value or AsyncError for stream errors.

Implementation

@override
FutureOr<void> subscribe(void Function(AsyncState<T> state) emit) async {
  final completer = Completer<void>();
  _sub = _stream.listen(
    (data) => emit(AsyncSuccess(data)),
    onError: (e, st) => emit(AsyncError(e, st)),
    onDone: completer.complete,
  );
  await completer.future;
}