Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // States shared by single/multi stream implementations. | 7 // States shared by single/multi stream implementations. |
| 8 | 8 |
| 9 // Completion state of the stream. | 9 // Completion state of the stream. |
| 10 /// Initial and default state where the stream can receive and send events. | 10 /// Initial and default state where the stream can receive and send events. |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 | 948 |
| 949 void pause([Future resumeSignal]) { | 949 void pause([Future resumeSignal]) { |
| 950 if (!_isSubscribed) return; | 950 if (!_isSubscribed) return; |
| 951 _source._pause(this, resumeSignal); | 951 _source._pause(this, resumeSignal); |
| 952 } | 952 } |
| 953 | 953 |
| 954 void resume() { | 954 void resume() { |
| 955 if (!_isSubscribed || !isPaused) return; | 955 if (!_isSubscribed || !isPaused) return; |
| 956 _source._resume(this, false); | 956 _source._resume(this, false); |
| 957 } | 957 } |
| 958 | |
| 959 Future asFuture([var futureValue]) { | |
| 960 _FutureImpl<T> result = new _FutureImpl<T>(); | |
| 961 | |
| 962 // Overwrite the onDone and onError handlers. | |
| 963 onDone(() { result._setValue(futureValue); }); | |
| 964 onError((AsyncError error) { | |
| 965 cancel(); | |
|
Anders Johnsen
2013/04/15 09:15:47
Set unsubscribeOnError = true?
Lasse Reichstein Nielsen
2013/04/15 10:19:15
It's final, and if you overwrite onError again, wh
| |
| 966 result._setError(error); | |
| 967 }); | |
| 968 | |
| 969 return result; | |
| 970 } | |
| 958 } | 971 } |
| 959 | 972 |
| 960 // Internal helpers. | 973 // Internal helpers. |
| 961 | 974 |
| 962 // Types of the different handlers on a stream. Types used to type fields. | 975 // Types of the different handlers on a stream. Types used to type fields. |
| 963 typedef void _DataHandler<T>(T value); | 976 typedef void _DataHandler<T>(T value); |
| 964 typedef void _ErrorHandler(AsyncError error); | 977 typedef void _ErrorHandler(AsyncError error); |
| 965 typedef void _DoneHandler(); | 978 typedef void _DoneHandler(); |
| 966 | 979 |
| 967 | 980 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1329 onError: this._addError, | 1342 onError: this._addError, |
| 1330 onDone: this._close); | 1343 onDone: this._close); |
| 1331 } else { | 1344 } else { |
| 1332 // TODO(lrn): Check why this can happen. | 1345 // TODO(lrn): Check why this can happen. |
| 1333 if (_subscription == null) return; | 1346 if (_subscription == null) return; |
| 1334 _subscription.cancel(); | 1347 _subscription.cancel(); |
| 1335 _subscription = null; | 1348 _subscription = null; |
| 1336 } | 1349 } |
| 1337 } | 1350 } |
| 1338 } | 1351 } |
| OLD | NEW |