Created
March 9, 2020 06:32
-
-
Save AlexKenbo/127b7c22e66fd31f23e23a5eaef46265 to your computer and use it in GitHub Desktop.
Single subscription vs Broadcast streams
This file contains hidden or 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() { | |
var streamController = StreamController(); | |
streamController.stream.listen(print); | |
//streamController.stream.listen(print); // ошибка: поток уже слушается, разкомментируйте строку, чтобы увидеть | |
streamController.sink.add('Одиночная подписка: 1'); | |
streamController.sink.add('Одиночная подписка: 2'); | |
var controller = StreamController<String>.broadcast(); | |
controller.stream.listen(print); | |
controller.stream.listen(print); | |
controller.sink.add('широковещательный поток: 1'); | |
controller.sink.add('широковещательный поток: 2'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment