Skip to content

Instantly share code, notes, and snippets.

@madmag77
Last active March 6, 2021 09:43
Show Gist options
  • Save madmag77/38d71961431781db468de8a357bb2f58 to your computer and use it in GitHub Desktop.
Save madmag77/38d71961431781db468de8a357bb2f58 to your computer and use it in GitHub Desktop.
[Dart article] Exceptions in streams 1
import 'dart:async';
void main(List<String> arguments) async {
startListener(getStream());
}
Stream<int> getStream() {
final intsController = StreamController<int>.broadcast();
int i = 42;
Timer.periodic(Duration(seconds: 1), (timer) {
i += 1;
if (i == 46) throw '[Stream] Bad thing happens!';
intsController.add(i);
});
return intsController.stream;
}
void startListener(Stream<int> ints) {
ints.listen((event) {
print(event);
if (event == 44) {
throw '[Listener] Bad thing happens!';
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment