Created with <3 with dartpad.dev.
Last active
May 19, 2023 03:37
-
-
Save noboru-i/d7c026ccae536684a64c080243ec4900 to your computer and use it in GitHub Desktop.
bustling-marble-3699
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'; | |
| Future<void> main() async { | |
| final controller = StreamController<int>(); | |
| startSender(controller); | |
| await for (int n in controller.stream) { | |
| print('consume $n'); | |
| } | |
| } | |
| Future<void> startSender(StreamController controller) async { | |
| await Future<void>.delayed(const Duration(milliseconds: 1000)); | |
| controller.add(1); | |
| await Future<void>.delayed(const Duration(milliseconds: 1000)); | |
| controller.add(2); | |
| await Future<void>.delayed(const Duration(milliseconds: 1000)); | |
| controller.add(3); | |
| await Future<void>.delayed(const Duration(milliseconds: 1000)); | |
| controller.add(4); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment