Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickmeinhold/03d99d8fe47e64210ce6e6c33fabf7a4 to your computer and use it in GitHub Desktop.
Save nickmeinhold/03d99d8fe47e64210ce6e6c33fabf7a4 to your computer and use it in GitHub Desktop.
Closing a StreamController calls onCancel and emits done event
import 'dart:async';
void main() {
var controller;
controller = StreamController(onListen: () {
for (final number in [1, 2]) {
controller.add(number);
}
controller.close();
},
onCancel: () => print('onCancel'));
controller.stream.listen(print, onDone: () => print('onDone'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment