OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library async.lazy_stream; | |
6 | |
7 import "dart:async"; | 5 import "dart:async"; |
8 | 6 |
9 import "stream_completer.dart"; | 7 import "stream_completer.dart"; |
10 | 8 |
11 /// A [Stream] wrapper that forwards to another [Stream] that's initialized | 9 /// A [Stream] wrapper that forwards to another [Stream] that's initialized |
12 /// lazily. | 10 /// lazily. |
13 /// | 11 /// |
14 /// This class allows a concrete `Stream` to be created only once it has a | 12 /// This class allows a concrete `Stream` to be created only once it has a |
15 /// listener. It's useful to wrapping APIs that do expensive computation to | 13 /// listener. It's useful to wrapping APIs that do expensive computation to |
16 /// produce a `Stream`. | 14 /// produce a `Stream`. |
(...skipping 25 matching lines...) Expand all Loading... |
42 var result = callback(); | 40 var result = callback(); |
43 | 41 |
44 Stream stream = result is Future | 42 Stream stream = result is Future |
45 ? StreamCompleter.fromFuture(result) | 43 ? StreamCompleter.fromFuture(result) |
46 : result; | 44 : result; |
47 | 45 |
48 return stream.listen(onData, | 46 return stream.listen(onData, |
49 onError: onError, onDone: onDone, cancelOnError: cancelOnError); | 47 onError: onError, onDone: onDone, cancelOnError: cancelOnError); |
50 } | 48 } |
51 } | 49 } |
OLD | NEW |