| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 }, | 332 }, |
| 333 onError: future._setError, | 333 onError: future._setError, |
| 334 onDone: () { | 334 onDone: () { |
| 335 future._setValue(false); | 335 future._setValue(false); |
| 336 }, | 336 }, |
| 337 cancelOnError: true); | 337 cancelOnError: true); |
| 338 return future; | 338 return future; |
| 339 } | 339 } |
| 340 | 340 |
| 341 /** | 341 /** |
| 342 * Executes [action] on each data event of the stream. |
| 343 * |
| 344 * Completes the returned [Future] when all events of the stream |
| 345 * have been processed. Completes the future with an error if the |
| 346 * stream has an error event, or if [action] throws. |
| 347 */ |
| 348 Future forEach(void action(T element)) { |
| 349 _FutureImpl future = new _FutureImpl(); |
| 350 StreamSubscription subscription; |
| 351 subscription = this.listen( |
| 352 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 353 // checked mode. http://dartbug.com/7733 |
| 354 (/*T*/ element) { |
| 355 _runUserCode( |
| 356 () => action(element), |
| 357 (_) {}, |
| 358 _cancelAndError(subscription, future) |
| 359 ); |
| 360 }, |
| 361 onError: future._setError, |
| 362 onDone: () { |
| 363 future._setValue(null); |
| 364 }, |
| 365 cancelOnError: true); |
| 366 return future; |
| 367 } |
| 368 |
| 369 /** |
| 342 * Checks whether [test] accepts all elements provided by this stream. | 370 * Checks whether [test] accepts all elements provided by this stream. |
| 343 * | 371 * |
| 344 * Completes the [Future] when the answer is known. | 372 * Completes the [Future] when the answer is known. |
| 345 * If this stream reports an error, the [Future] will report that error. | 373 * If this stream reports an error, the [Future] will report that error. |
| 346 */ | 374 */ |
| 347 Future<bool> every(bool test(T element)) { | 375 Future<bool> every(bool test(T element)) { |
| 348 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 376 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 349 StreamSubscription subscription; | 377 StreamSubscription subscription; |
| 350 subscription = this.listen( | 378 subscription = this.listen( |
| 351 // TODO(ahe): Restore type when feature is implemented in dart2js | 379 // TODO(ahe): Restore type when feature is implemented in dart2js |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 } | 1205 } |
| 1178 | 1206 |
| 1179 class _EventOutputSinkWrapper<T> extends EventSink<T> { | 1207 class _EventOutputSinkWrapper<T> extends EventSink<T> { |
| 1180 _EventOutputSink _sink; | 1208 _EventOutputSink _sink; |
| 1181 _EventOutputSinkWrapper(this._sink); | 1209 _EventOutputSinkWrapper(this._sink); |
| 1182 | 1210 |
| 1183 void add(T data) { _sink._sendData(data); } | 1211 void add(T data) { _sink._sendData(data); } |
| 1184 void addError(error) { _sink._sendError(error); } | 1212 void addError(error) { _sink._sendError(error); } |
| 1185 void close() { _sink._sendDone(); } | 1213 void close() { _sink._sendDone(); } |
| 1186 } | 1214 } |
| OLD | NEW |