Skip to content

Instantly share code, notes, and snippets.

@Devlonoah
Created October 1, 2021 18:17
Show Gist options
  • Save Devlonoah/be8c53c867d9f7d2d3844ac702ebbc24 to your computer and use it in GitHub Desktop.
Save Devlonoah/be8c53c867d9f7d2d3844ac702ebbc24 to your computer and use it in GitHub Desktop.
Listening to stream of data by using streamsubscription
import "dart:async";
void main() {
StreamSubscription<int> data;
data = createStream([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]).listen((x) {
print(x);
});
data.onDone(() {
print('stream of data is done emitting');
});
data.onError((x) {
print('an error occured');
});
}
Stream<int> createStream(List<int> maxCount) async* {
for (var coun in maxCount) {
await Future.delayed(Duration(seconds: 1));
yield coun;
}
}
// Stream shitStream(Stream stream)async*{
// stream.listen((x){
// print("new stream $x");
// });
// }
class GeneralException implements Exception {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment