start method

void start()

Invokes the factory and listens once. Factory/listen failures are events.

Implementation

void start() {
  if (_started || _stopped) return;
  _started = true;
  final make = _source!;
  _source = null;
  try {
    final incoming = make();
    if (_stopped) return;
    _broadcast = incoming.isBroadcast;
    final cancelFailed = _onCancelFailed;
    final subscription = incoming.listen(
      (event) => _onData?.call(event),
      onError: (Object error, StackTrace stack) =>
          _onError?.call(error, stack),
      onDone: _complete,
    );
    if (_stopped) {
      _cancel(subscription, cancelFailed);
    } else {
      _subscription = subscription;
      if (_paused && (pauseBroadcast || !_broadcast)) subscription.pause();
    }
  } on Object catch (error, stack) {
    try {
      _onError?.call(error, stack);
    } finally {
      _complete();
    }
  }
}