Created
October 1, 2021 18:17
-
-
Save Devlonoah/be8c53c867d9f7d2d3844ac702ebbc24 to your computer and use it in GitHub Desktop.
Listening to stream of data by using streamsubscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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