Skip to content

Instantly share code, notes, and snippets.

@noboru-i
Last active May 19, 2023 03:37
Show Gist options
  • Select an option

  • Save noboru-i/d7c026ccae536684a64c080243ec4900 to your computer and use it in GitHub Desktop.

Select an option

Save noboru-i/d7c026ccae536684a64c080243ec4900 to your computer and use it in GitHub Desktop.
bustling-marble-3699

bustling-marble-3699

Created with <3 with dartpad.dev.

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