OLD | NEW |
1 --- | 1 --- |
2 layout: tutorial | 2 layout: tutorial |
3 title: "Asynchronous Programming: Streams" | 3 title: "Asynchronous Programming: Streams" |
4 description: | 4 description: |
5 Learn how to consume single-subscriber and broadcast streams. | 5 Learn how to consume single-subscriber and broadcast streams. |
6 tutorial: | 6 tutorial: |
7 id: streams | 7 id: streams |
8 next: fetchdata/ | 8 next: fetchdata/ |
9 next-title: "Fetch Data Dynamically" | 9 next-title: "Fetch Data Dynamically" |
10 prev: futures/ | 10 prev: futures/ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 main() async { | 110 main() async { |
111 var stream = countStream(10); | 111 var stream = countStream(10); |
112 var sum = await sumStream(stream); | 112 var sum = await sumStream(stream); |
113 print(sum); // 55 | 113 print(sum); // 55 |
114 } | 114 } |
115 {% endcomment %} | 115 {% endcomment %} |
116 | 116 |
117 <iframe | 117 <iframe |
118 src="{{site.custom.dartpad.embed-prefix}}?id=15d5ef986238c97dbc14&horizontalRati
o=70&verticalRatio=80" | 118 src="{{site.custom.dartpad.embed-dart-prefix}}?id=15d5ef986238c97dbc14&horizonta
lRatio=70&verticalRatio=80" |
119 width="100%" | 119 width="100%" |
120 height="500px" | 120 height="500px" |
121 style="border: 1px solid #ccc;"> | 121 style="border: 1px solid #ccc;"> |
122 </iframe> | 122 </iframe> |
123 | 123 |
124 <aside class="alert alert-info" markdown="1"> | 124 <aside class="alert alert-info" markdown="1"> |
125 **Note:** | 125 **Note:** |
126 Click run ( <img src="/imgs/run.png"/> ) | 126 Click run ( <img src="/imgs/run.png"/> ) |
127 to see the result in the **Console output**. | 127 to see the result in the **Console output**. |
128 </aside> | 128 </aside> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 main() async { | 181 main() async { |
182 var stream = countStream(10); | 182 var stream = countStream(10); |
183 var sum = await sumStream(stream); | 183 var sum = await sumStream(stream); |
184 print(sum); // -1 | 184 print(sum); // -1 |
185 } | 185 } |
186 {% endcomment %} | 186 {% endcomment %} |
187 | 187 |
188 <iframe | 188 <iframe |
189 src="{{site.custom.dartpad.embed-prefix}}?id=38feef09be9b1e7b5136&horizontalRati
o=70&verticalRatio=80" | 189 src="{{site.custom.dartpad.embed-dart-prefix}}?id=38feef09be9b1e7b5136&horizonta
lRatio=70&verticalRatio=80" |
190 width="100%" | 190 width="100%" |
191 height="450px" | 191 height="450px" |
192 style="border: 1px solid #ccc;"> | 192 style="border: 1px solid #ccc;"> |
193 </iframe> | 193 </iframe> |
194 | 194 |
195 <aside class="alert alert-info" markdown="1"> | 195 <aside class="alert alert-info" markdown="1"> |
196 **Note:** | 196 **Note:** |
197 Click run ( <img src="/imgs/run.png"/> ) | 197 Click run ( <img src="/imgs/run.png"/> ) |
198 to see the result in the **Console output**. | 198 to see the result in the **Console output**. |
199 </aside> | 199 </aside> |
(...skipping 22 matching lines...) Expand all Loading... |
222 | 222 |
223 main() async { | 223 main() async { |
224 var data = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]; | 224 var data = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10]; |
225 var stream = new Stream.fromIterable(data); | 225 var stream = new Stream.fromIterable(data); |
226 var lastPositive = await lastPositive(stream); | 226 var lastPositive = await lastPositive(stream); |
227 print(lastPositive); // 9 | 227 print(lastPositive); // 9 |
228 } | 228 } |
229 {% endcomment %} | 229 {% endcomment %} |
230 | 230 |
231 <iframe | 231 <iframe |
232 src="{{site.custom.dartpad.embed-prefix}}?id=da80b1e7eed75db53ef3&horizontalRati
o=70&verticalRatio=80" | 232 src="{{site.custom.dartpad.embed-dart-prefix}}?id=da80b1e7eed75db53ef3&horizonta
lRatio=70&verticalRatio=80" |
233 width="100%" | 233 width="100%" |
234 height="450px" | 234 height="450px" |
235 style="border: 1px solid #ccc;"> | 235 style="border: 1px solid #ccc;"> |
236 </iframe> | 236 </iframe> |
237 | 237 |
238 <aside class="alert alert-info" markdown="1"> | 238 <aside class="alert alert-info" markdown="1"> |
239 **Note:** | 239 **Note:** |
240 Click run ( <img src="/imgs/run.png"/> ) | 240 Click run ( <img src="/imgs/run.png"/> ) |
241 to see the result in the **Console output**. | 241 to see the result in the **Console output**. |
242 </aside> | 242 </aside> |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 486 |
487 ## What next? {#what-next} | 487 ## What next? {#what-next} |
488 | 488 |
489 The [Write HTTP Clients & Servers](/docs/tutorials/httpserver/) and | 489 The [Write HTTP Clients & Servers](/docs/tutorials/httpserver/) and |
490 [Write Command-Line Apps](/docs/tutorials/cmdline/) tutorials include | 490 [Write Command-Line Apps](/docs/tutorials/cmdline/) tutorials include |
491 examples that use streams. | 491 examples that use streams. |
492 | 492 |
493 {% endcapture %} | 493 {% endcapture %} |
494 | 494 |
495 {% include tutorial.html %} | 495 {% include tutorial.html %} |
OLD | NEW |