Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: sdk/lib/async/stream.dart

Issue 11794044: Add Stream.fromIterable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Fix bug hit by new test. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/async/stream_impl.dart » ('j') | sdk/lib/core/iterable.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // part of dart.async; 5 // part of dart.async;
6 6
7 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 // Core Stream types 8 // Core Stream types
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
11 abstract class Stream<T> { 11 abstract class Stream<T> {
12 Stream(); 12 Stream();
13 13
14 factory Stream.fromFuture(Future<T> future) { 14 factory Stream.fromFuture(Future<T> future) {
15 var controller = new StreamController<T>(); 15 _StreamImpl<T> stream = new _MultiStreamImpl<T>();
16 future.then((value) { 16 future.then((value) {
17 controller.add(value); 17 stream._add(value);
18 controller.close(); 18 stream._close();
19 }, 19 },
20 onError: (error) { 20 onError: (error) {
21 controller.signalError(error); 21 stream._signalError(error);
22 controller.close(); 22 stream._close();
23 }); 23 });
24 return controller.stream; 24 return stream;
25 } 25 }
26 26
27 /** 27 /**
28 * Creates a single-subscription stream that gets its data from [data].
29 */
30 factory Stream.fromIterable(Iterable<T> data) {
31 return new _IterableSingleStreamImpl<T>(data);
32 }
33
34 /**
28 * Stream that outputs events from the [sources] in cyclic order. 35 * Stream that outputs events from the [sources] in cyclic order.
29 * 36 *
30 * The merged streams are paused and resumed in order to ensure the proper 37 * The merged streams are paused and resumed in order to ensure the proper
31 * order of output events. 38 * order of output events.
32 */ 39 */
33 factory Stream.cyclic(Iterable<Stream> sources) { 40 factory Stream.cyclic(Iterable<Stream> sources) {
34 return new CyclicScheduleStream<T>(sources); 41 return new CyclicScheduleStream<T>(sources);
35 } 42 }
36 43
37 /** 44 /**
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 sink.signalError(error); 840 sink.signalError(error);
834 } 841 }
835 842
836 /** 843 /**
837 * Handle an incoming done event. 844 * Handle an incoming done event.
838 */ 845 */
839 void handleDone(StreamSink<T> sink) { 846 void handleDone(StreamSink<T> sink) {
840 sink.close(); 847 sink.close();
841 } 848 }
842 } 849 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/async/stream_impl.dart » ('j') | sdk/lib/core/iterable.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698