Last active
March 6, 2021 09:43
-
-
Save madmag77/38d71961431781db468de8a357bb2f58 to your computer and use it in GitHub Desktop.
[Dart article] Exceptions in streams 1
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(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