■ Stream<T> 클래스를 사용하는 방법을 보여준다.
▶ 예제 코드 (DART)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import 'dart:async'; Stream<int> countStream(int count) async* { for (int i = 1; i <= count; i++) { print('countStream : $i'); yield i; } } Future<int> sumStream(Stream<int> stream) async { int summary = 0; await for (int value in stream) { print('sumStream : $value'); summary += value; } return summary; } main() async { Stream<int> stream = countStream(10); int summary = await sumStream(stream); print(summary); } |