Created
January 6, 2020 13:41
-
-
Save hpoul/422f9383406513b9016f235833c61154 to your computer and use it in GitHub Desktop.
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() 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