| 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 result._setError(e); | 321 result._setError(e); |
| 322 }, | 322 }, |
| 323 onDone: () { | 323 onDone: () { |
| 324 result._setValue(value); | 324 result._setValue(value); |
| 325 }, | 325 }, |
| 326 cancelOnError: true); | 326 cancelOnError: true); |
| 327 return result; | 327 return result; |
| 328 } | 328 } |
| 329 | 329 |
| 330 /** | 330 /** |
| 331 * Collects string of data events' string representations. |
| 332 * |
| 333 * If [separator] is provided, it is inserted between any two |
| 334 * elements. |
| 335 * |
| 336 * Any error in the stream causes the future to complete with that |
| 337 * error. Otherwise it completes with the collected string when |
| 338 * the "done" event arrives. |
| 339 */ |
| 340 Future<String> join([String separator = ""]) { |
| 341 _FutureImpl<String> result = new _FutureImpl<String>(); |
| 342 StringBuffer buffer = new StringBuffer(); |
| 343 StreamSubscription subscription; |
| 344 bool first = true; |
| 345 subscription = this.listen( |
| 346 (T element) { |
| 347 if (!first) { |
| 348 buffer.write(separator); |
| 349 } |
| 350 first = false; |
| 351 try { |
| 352 buffer.write(element); |
| 353 } catch (e, s) { |
| 354 subscription.cancel(); |
| 355 result._setError(_asyncError(e, s)); |
| 356 } |
| 357 }, |
| 358 onError: (e) { |
| 359 result._setError(e); |
| 360 }, |
| 361 onDone: () { |
| 362 result._setValue(buffer.toString()); |
| 363 }, |
| 364 cancelOnError: true); |
| 365 return result; |
| 366 } |
| 367 |
| 368 /** |
| 331 * Checks whether [needle] occurs in the elements provided by this stream. | 369 * Checks whether [needle] occurs in the elements provided by this stream. |
| 332 * | 370 * |
| 333 * Completes the [Future] when the answer is known. | 371 * Completes the [Future] when the answer is known. |
| 334 * If this stream reports an error, the [Future] will report that error. | 372 * If this stream reports an error, the [Future] will report that error. |
| 335 */ | 373 */ |
| 336 Future<bool> contains(Object needle) { | 374 Future<bool> contains(Object needle) { |
| 337 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 375 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 338 StreamSubscription subscription; | 376 StreamSubscription subscription; |
| 339 subscription = this.listen( | 377 subscription = this.listen( |
| 340 // TODO(ahe): Restore type when feature is implemented in dart2js | 378 // TODO(ahe): Restore type when feature is implemented in dart2js |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 * | 1289 * |
| 1252 * If a [moveNext] call has been made, it will complete with `false` as value, | 1290 * If a [moveNext] call has been made, it will complete with `false` as value, |
| 1253 * as will all further calls to [moveNext]. | 1291 * as will all further calls to [moveNext]. |
| 1254 * | 1292 * |
| 1255 * If you need to stop listening for values before the stream iterator is | 1293 * If you need to stop listening for values before the stream iterator is |
| 1256 * automatically closed, you must call [cancel] to ensure that the stream | 1294 * automatically closed, you must call [cancel] to ensure that the stream |
| 1257 * is properly closed. | 1295 * is properly closed. |
| 1258 */ | 1296 */ |
| 1259 void cancel(); | 1297 void cancel(); |
| 1260 } | 1298 } |
| OLD | NEW |