Skip to content

Instantly share code, notes, and snippets.

@hpoul
Created January 6, 2020 13:41
Show Gist options
  • Save hpoul/422f9383406513b9016f235833c61154 to your computer and use it in GitHub Desktop.
Save hpoul/422f9383406513b9016f235833c61154 to your computer and use it in GitHub Desktop.
import 'dart:async';
void main() async {
final a = StreamController.broadcast(onListen: () {
print('onListen.');
}, onCancel: () {
print('onCancel');
});
final aasub = a.stream.listen((data) {
print('aa: $data');
});
print('started.');
a.add(1);
a.add(2);
a.add(3);
final bbsub = a.stream.listen((data) {
print('bb: $data');
});
a.add(4);
await Future.delayed(Duration(milliseconds: 10));
await aasub.cancel();
await bbsub.cancel();
print('canceled.');
await Future.delayed(Duration(milliseconds: 10));
a.add(5);
await Future.delayed(Duration(milliseconds: 10));
final ccsub = a.stream.listen((data) {
print('cc: $data');
});
a.add(6);
await Future.delayed(Duration(milliseconds: 10));
await ccsub.cancel();
a.close();
print('done.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment