A subscription on events from a Stream.
When you listen on a Stream using Stream.listen, a StreamSubscription object is returned.
The subscription provides events to the listener, and holds the callbacks used to handle the events. The subscription can also be used to unsubscribe from the events, or to temporarily pause the events from the stream.
Example:
final stream = Stream.periodic(const Duration(seconds: 1), (i) => i * i)
.take(10);
final subscription = stream.listen(print); // A StreamSubscription<int>. To pause the subscription, use pause.
// Do some work. subscription.pause(); print(subscription.isPaused); // true
To resume after the pause, use resume.
// Do some work. subscription.resume(); print(subscription.isPaused); // false
To cancel the subscription, use cancel.
// Do some work. subscription.cancel();
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-async/StreamSubscription-class.html