SubscriptionStream<T> constructor

SubscriptionStream<T>(
  1. StreamSubscription<T> subscription
)

Create a single-subscription Stream from subscription.

The subscription should not be paused. This class will not resume prior pauses, so being paused is indistinguishable from not providing any events.

If the subscription doesn't send any done events, neither will this stream. That may be an issue if subscription was made to cancel on an error.

Implementation

SubscriptionStream(StreamSubscription<T> subscription)
    : _source = subscription {
  var source = _source!;
  source.pause();
  // Clear callbacks to avoid keeping them alive unnecessarily.
  source.onData(null);
  source.onError(null);
  source.onDone(null);
}