| 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 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
| 8 // Core Stream types | 8 // Core Stream types |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return streamTransformer.bind(this); | 206 return streamTransformer.bind(this); |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 /** Reduces a sequence of values by repeatedly applying [combine]. */ | 210 /** Reduces a sequence of values by repeatedly applying [combine]. */ |
| 211 Future reduce(var initialValue, combine(var previous, T element)) { | 211 Future reduce(var initialValue, combine(var previous, T element)) { |
| 212 _FutureImpl result = new _FutureImpl(); | 212 _FutureImpl result = new _FutureImpl(); |
| 213 var value = initialValue; | 213 var value = initialValue; |
| 214 StreamSubscription subscription; | 214 StreamSubscription subscription; |
| 215 subscription = this.listen( | 215 subscription = this.listen( |
| 216 (T element) { | 216 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 217 // checked mode. http://dartbug.com/7733 |
| 218 (/*T*/ element) { |
| 217 _runUserCode( | 219 _runUserCode( |
| 218 () => combine(value, element), | 220 () => combine(value, element), |
| 219 (result) { value = result; }, | 221 (result) { value = result; }, |
| 220 _cancelAndError(subscription, result) | 222 _cancelAndError(subscription, result) |
| 221 ); | 223 ); |
| 222 }, | 224 }, |
| 223 onError: (AsyncError e) { | 225 onError: (AsyncError e) { |
| 224 result._setError(e); | 226 result._setError(e); |
| 225 }, | 227 }, |
| 226 onDone: () { | 228 onDone: () { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 250 /** | 252 /** |
| 251 * Check whether [match] occurs in the elements provided by this stream. | 253 * Check whether [match] occurs in the elements provided by this stream. |
| 252 * | 254 * |
| 253 * Completes the [Future] when the answer is known. | 255 * Completes the [Future] when the answer is known. |
| 254 * If this stream reports an error, the [Future] will report that error. | 256 * If this stream reports an error, the [Future] will report that error. |
| 255 */ | 257 */ |
| 256 Future<bool> contains(T match) { | 258 Future<bool> contains(T match) { |
| 257 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 259 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 258 StreamSubscription subscription; | 260 StreamSubscription subscription; |
| 259 subscription = this.listen( | 261 subscription = this.listen( |
| 260 (T element) { | 262 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 263 // checked mode. http://dartbug.com/7733 |
| 264 (/*T*/ element) { |
| 261 _runUserCode( | 265 _runUserCode( |
| 262 () => match(element), | 266 () => match(element), |
| 263 (bool isMatch) { | 267 (bool isMatch) { |
| 264 if (isMatch) { | 268 if (isMatch) { |
| 265 subscription.cancel(); | 269 subscription.cancel(); |
| 266 future._setValue(element); | 270 future._setValue(element); |
| 267 } | 271 } |
| 268 }, | 272 }, |
| 269 _cancelAndError(subscription, future) | 273 _cancelAndError(subscription, future) |
| 270 ); | 274 ); |
| 271 }, | 275 }, |
| 272 onError: future._setError, | 276 onError: future._setError, |
| 273 onDone: () { | 277 onDone: () { |
| 274 future._setValue(false); | 278 future._setValue(false); |
| 275 }, | 279 }, |
| 276 unsubscribeOnError: true); | 280 unsubscribeOnError: true); |
| 277 return future; | 281 return future; |
| 278 } | 282 } |
| 279 | 283 |
| 280 /** | 284 /** |
| 281 * Check whether [test] accepts all elements provided by this stream. | 285 * Check whether [test] accepts all elements provided by this stream. |
| 282 * | 286 * |
| 283 * Completes the [Future] when the answer is known. | 287 * Completes the [Future] when the answer is known. |
| 284 * If this stream reports an error, the [Future] will report that error. | 288 * If this stream reports an error, the [Future] will report that error. |
| 285 */ | 289 */ |
| 286 Future<bool> every(bool test(T element)) { | 290 Future<bool> every(bool test(T element)) { |
| 287 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 291 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 288 StreamSubscription subscription; | 292 StreamSubscription subscription; |
| 289 subscription = this.listen( | 293 subscription = this.listen( |
| 290 (T element) { | 294 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 295 // checked mode. http://dartbug.com/7733 |
| 296 (/*T*/ element) { |
| 291 _runUserCode( | 297 _runUserCode( |
| 292 () => test(element), | 298 () => test(element), |
| 293 (bool isMatch) { | 299 (bool isMatch) { |
| 294 if (!isMatch) { | 300 if (!isMatch) { |
| 295 subscription.cancel(); | 301 subscription.cancel(); |
| 296 future._setValue(false); | 302 future._setValue(false); |
| 297 } | 303 } |
| 298 }, | 304 }, |
| 299 _cancelAndError(subscription, future) | 305 _cancelAndError(subscription, future) |
| 300 ); | 306 ); |
| 301 }, | 307 }, |
| 302 onError: future._setError, | 308 onError: future._setError, |
| 303 onDone: () { | 309 onDone: () { |
| 304 future._setValue(true); | 310 future._setValue(true); |
| 305 }, | 311 }, |
| 306 unsubscribeOnError: true); | 312 unsubscribeOnError: true); |
| 307 return future; | 313 return future; |
| 308 } | 314 } |
| 309 | 315 |
| 310 /** | 316 /** |
| 311 * Check whether [test] accepts any element provided by this stream. | 317 * Check whether [test] accepts any element provided by this stream. |
| 312 * | 318 * |
| 313 * Completes the [Future] when the answer is known. | 319 * Completes the [Future] when the answer is known. |
| 314 * If this stream reports an error, the [Future] will report that error. | 320 * If this stream reports an error, the [Future] will report that error. |
| 315 */ | 321 */ |
| 316 Future<bool> any(bool test(T element)) { | 322 Future<bool> any(bool test(T element)) { |
| 317 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 323 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 318 StreamSubscription subscription; | 324 StreamSubscription subscription; |
| 319 subscription = this.listen( | 325 subscription = this.listen( |
| 320 (T element) { | 326 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 327 // checked mode. http://dartbug.com/7733 |
| 328 (/*T*/ element) { |
| 321 _runUserCode( | 329 _runUserCode( |
| 322 () => test(element), | 330 () => test(element), |
| 323 (bool isMatch) { | 331 (bool isMatch) { |
| 324 if (isMatch) { | 332 if (isMatch) { |
| 325 subscription.cancel(); | 333 subscription.cancel(); |
| 326 future._setValue(true); | 334 future._setValue(true); |
| 327 } | 335 } |
| 328 }, | 336 }, |
| 329 _cancelAndError(subscription, future) | 337 _cancelAndError(subscription, future) |
| 330 ); | 338 ); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 361 * be a [Comparator]). | 369 * be a [Comparator]). |
| 362 * | 370 * |
| 363 * If [compare] is omitted, it defaults to [Comparable.compare]. | 371 * If [compare] is omitted, it defaults to [Comparable.compare]. |
| 364 */ | 372 */ |
| 365 Future<T> min([int compare(T a, T b)]) { | 373 Future<T> min([int compare(T a, T b)]) { |
| 366 if (compare == null) compare = Comparable.compare; | 374 if (compare == null) compare = Comparable.compare; |
| 367 _FutureImpl<T> future = new _FutureImpl<T>(); | 375 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 368 StreamSubscription subscription; | 376 StreamSubscription subscription; |
| 369 T min = null; | 377 T min = null; |
| 370 subscription = this.listen( | 378 subscription = this.listen( |
| 371 (T value) { | 379 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 380 // checked mode. http://dartbug.com/7733 |
| 381 (/*T*/ value) { |
| 372 min = value; | 382 min = value; |
| 373 subscription.onData((T value) { | 383 subscription.onData((T value) { |
| 374 _runUserCode( | 384 _runUserCode( |
| 375 () => compare(min, value) > 0, | 385 () => compare(min, value) > 0, |
| 376 (bool foundSmaller) { | 386 (bool foundSmaller) { |
| 377 if (foundSmaller) { | 387 if (foundSmaller) { |
| 378 min = value; | 388 min = value; |
| 379 } | 389 } |
| 380 }, | 390 }, |
| 381 _cancelAndError(subscription, future) | 391 _cancelAndError(subscription, future) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 400 * be a [Comparator]). | 410 * be a [Comparator]). |
| 401 * | 411 * |
| 402 * If [compare] is omitted, it defaults to [Comparable.compare]. | 412 * If [compare] is omitted, it defaults to [Comparable.compare]. |
| 403 */ | 413 */ |
| 404 Future<T> max([int compare(T a, T b)]) { | 414 Future<T> max([int compare(T a, T b)]) { |
| 405 if (compare == null) compare = Comparable.compare; | 415 if (compare == null) compare = Comparable.compare; |
| 406 _FutureImpl<T> future = new _FutureImpl<T>(); | 416 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 407 StreamSubscription subscription; | 417 StreamSubscription subscription; |
| 408 T max = null; | 418 T max = null; |
| 409 subscription = this.listen( | 419 subscription = this.listen( |
| 410 (T value) { | 420 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 421 // checked mode. http://dartbug.com/7733 |
| 422 (/*T*/ value) { |
| 411 max = value; | 423 max = value; |
| 412 subscription.onData((T value) { | 424 subscription.onData((T value) { |
| 413 _runUserCode( | 425 _runUserCode( |
| 414 () => compare(max, value) < 0, | 426 () => compare(max, value) < 0, |
| 415 (bool foundGreater) { | 427 (bool foundGreater) { |
| 416 if (foundGreater) { | 428 if (foundGreater) { |
| 417 max = value; | 429 max = value; |
| 418 } | 430 } |
| 419 }, | 431 }, |
| 420 _cancelAndError(subscription, future) | 432 _cancelAndError(subscription, future) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 445 }, | 457 }, |
| 446 unsubscribeOnError: true); | 458 unsubscribeOnError: true); |
| 447 return future; | 459 return future; |
| 448 } | 460 } |
| 449 | 461 |
| 450 /** Collect the data of this stream in a [List]. */ | 462 /** Collect the data of this stream in a [List]. */ |
| 451 Future<List<T>> toList() { | 463 Future<List<T>> toList() { |
| 452 List<T> result = <T>[]; | 464 List<T> result = <T>[]; |
| 453 _FutureImpl<List<T>> future = new _FutureImpl<List<T>>(); | 465 _FutureImpl<List<T>> future = new _FutureImpl<List<T>>(); |
| 454 this.listen( | 466 this.listen( |
| 455 (T data) { | 467 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 468 // checked mode. http://dartbug.com/7733 |
| 469 (/*T*/ data) { |
| 456 result.add(data); | 470 result.add(data); |
| 457 }, | 471 }, |
| 458 onError: future._setError, | 472 onError: future._setError, |
| 459 onDone: () { | 473 onDone: () { |
| 460 future._setValue(result); | 474 future._setValue(result); |
| 461 }, | 475 }, |
| 462 unsubscribeOnError: true); | 476 unsubscribeOnError: true); |
| 463 return future; | 477 return future; |
| 464 } | 478 } |
| 465 | 479 |
| 466 /** Collect the data of this stream in a [Set]. */ | 480 /** Collect the data of this stream in a [Set]. */ |
| 467 Future<Set<T>> toSet() { | 481 Future<Set<T>> toSet() { |
| 468 Set<T> result = new Set<T>(); | 482 Set<T> result = new Set<T>(); |
| 469 _FutureImpl<Set<T>> future = new _FutureImpl<Set<T>>(); | 483 _FutureImpl<Set<T>> future = new _FutureImpl<Set<T>>(); |
| 470 this.listen( | 484 this.listen( |
| 471 (T data) { | 485 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 486 // checked mode. http://dartbug.com/7733 |
| 487 (/*T*/ data) { |
| 472 result.add(data); | 488 result.add(data); |
| 473 }, | 489 }, |
| 474 onError: future._setError, | 490 onError: future._setError, |
| 475 onDone: () { | 491 onDone: () { |
| 476 future._setValue(result); | 492 future._setValue(result); |
| 477 }, | 493 }, |
| 478 unsubscribeOnError: true); | 494 unsubscribeOnError: true); |
| 479 return future; | 495 return future; |
| 480 } | 496 } |
| 481 | 497 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 /** | 555 /** |
| 540 * Returns the first element. | 556 * Returns the first element. |
| 541 * | 557 * |
| 542 * If [this] is empty throws a [StateError]. Otherwise this method is | 558 * If [this] is empty throws a [StateError]. Otherwise this method is |
| 543 * equivalent to [:this.elementAt(0):] | 559 * equivalent to [:this.elementAt(0):] |
| 544 */ | 560 */ |
| 545 Future<T> get first { | 561 Future<T> get first { |
| 546 _FutureImpl<T> future = new _FutureImpl<T>(); | 562 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 547 StreamSubscription subscription; | 563 StreamSubscription subscription; |
| 548 subscription = this.listen( | 564 subscription = this.listen( |
| 549 (T value) { | 565 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 566 // checked mode. http://dartbug.com/7733 |
| 567 (/*T*/ value) { |
| 550 future._setValue(value); | 568 future._setValue(value); |
| 551 subscription.cancel(); | 569 subscription.cancel(); |
| 552 return; | 570 return; |
| 553 }, | 571 }, |
| 554 onError: future._setError, | 572 onError: future._setError, |
| 555 onDone: () { | 573 onDone: () { |
| 556 future._setError(new AsyncError(new StateError("No elements"))); | 574 future._setError(new AsyncError(new StateError("No elements"))); |
| 557 }, | 575 }, |
| 558 unsubscribeOnError: true); | 576 unsubscribeOnError: true); |
| 559 return future; | 577 return future; |
| 560 } | 578 } |
| 561 | 579 |
| 562 /** | 580 /** |
| 563 * Returns the last element. | 581 * Returns the last element. |
| 564 * | 582 * |
| 565 * If [this] is empty throws a [StateError]. | 583 * If [this] is empty throws a [StateError]. |
| 566 */ | 584 */ |
| 567 Future<T> get last { | 585 Future<T> get last { |
| 568 _FutureImpl<T> future = new _FutureImpl<T>(); | 586 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 569 T result = null; | 587 T result = null; |
| 570 bool foundResult = false; | 588 bool foundResult = false; |
| 571 StreamSubscription subscription; | 589 StreamSubscription subscription; |
| 572 subscription = this.listen( | 590 subscription = this.listen( |
| 573 (T value) { | 591 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 592 // checked mode. http://dartbug.com/7733 |
| 593 (/*T*/ value) { |
| 574 foundResult = true; | 594 foundResult = true; |
| 575 result = value; | 595 result = value; |
| 576 }, | 596 }, |
| 577 onError: future._setError, | 597 onError: future._setError, |
| 578 onDone: () { | 598 onDone: () { |
| 579 if (foundResult) { | 599 if (foundResult) { |
| 580 future._setValue(result); | 600 future._setValue(result); |
| 581 return; | 601 return; |
| 582 } | 602 } |
| 583 future._setError(new AsyncError(new StateError("No elements"))); | 603 future._setError(new AsyncError(new StateError("No elements"))); |
| 584 }, | 604 }, |
| 585 unsubscribeOnError: true); | 605 unsubscribeOnError: true); |
| 586 return future; | 606 return future; |
| 587 } | 607 } |
| 588 | 608 |
| 589 /** | 609 /** |
| 590 * Returns the single element. | 610 * Returns the single element. |
| 591 * | 611 * |
| 592 * If [this] is empty or has more than one element throws a [StateError]. | 612 * If [this] is empty or has more than one element throws a [StateError]. |
| 593 */ | 613 */ |
| 594 Future<T> get single { | 614 Future<T> get single { |
| 595 _FutureImpl<T> future = new _FutureImpl<T>(); | 615 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 596 T result = null; | 616 T result = null; |
| 597 bool foundResult = false; | 617 bool foundResult = false; |
| 598 StreamSubscription subscription; | 618 StreamSubscription subscription; |
| 599 subscription = this.listen( | 619 subscription = this.listen( |
| 600 (T value) { | 620 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 621 // checked mode. http://dartbug.com/7733 |
| 622 (/*T*/ value) { |
| 601 if (foundResult) { | 623 if (foundResult) { |
| 602 // This is the second element we get. | 624 // This is the second element we get. |
| 603 Error error = new StateError("More than one element"); | 625 Error error = new StateError("More than one element"); |
| 604 future._setError(new AsyncError(error)); | 626 future._setError(new AsyncError(error)); |
| 605 subscription.cancel(); | 627 subscription.cancel(); |
| 606 return; | 628 return; |
| 607 } | 629 } |
| 608 foundResult = true; | 630 foundResult = true; |
| 609 result = value; | 631 result = value; |
| 610 }, | 632 }, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 631 * becomes the value of the future. | 653 * becomes the value of the future. |
| 632 * | 654 * |
| 633 * If an error occurs, or if this stream ends without finding a match and | 655 * If an error occurs, or if this stream ends without finding a match and |
| 634 * with no [defaultValue] function provided, the future will receive an | 656 * with no [defaultValue] function provided, the future will receive an |
| 635 * error. | 657 * error. |
| 636 */ | 658 */ |
| 637 Future<T> firstMatching(bool test(T value), {T defaultValue()}) { | 659 Future<T> firstMatching(bool test(T value), {T defaultValue()}) { |
| 638 _FutureImpl<T> future = new _FutureImpl<T>(); | 660 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 639 StreamSubscription subscription; | 661 StreamSubscription subscription; |
| 640 subscription = this.listen( | 662 subscription = this.listen( |
| 641 (T value) { | 663 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 664 // checked mode. http://dartbug.com/7733 |
| 665 (/*T*/ value) { |
| 642 _runUserCode( | 666 _runUserCode( |
| 643 () => test(value), | 667 () => test(value), |
| 644 (bool isMatch) { | 668 (bool isMatch) { |
| 645 if (isMatch) { | 669 if (isMatch) { |
| 646 subscription.cancel(); | 670 subscription.cancel(); |
| 647 future._setValue(value); | 671 future._setValue(value); |
| 648 } | 672 } |
| 649 }, | 673 }, |
| 650 _cancelAndError(subscription, future) | 674 _cancelAndError(subscription, future) |
| 651 ); | 675 ); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 669 * As [firstMatching], except that the last matching element is found. | 693 * As [firstMatching], except that the last matching element is found. |
| 670 * That means that the result cannot be provided before this stream | 694 * That means that the result cannot be provided before this stream |
| 671 * is done. | 695 * is done. |
| 672 */ | 696 */ |
| 673 Future<T> lastMatching(bool test(T value), {T defaultValue()}) { | 697 Future<T> lastMatching(bool test(T value), {T defaultValue()}) { |
| 674 _FutureImpl<T> future = new _FutureImpl<T>(); | 698 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 675 T result = null; | 699 T result = null; |
| 676 bool foundResult = false; | 700 bool foundResult = false; |
| 677 StreamSubscription subscription; | 701 StreamSubscription subscription; |
| 678 subscription = this.listen( | 702 subscription = this.listen( |
| 679 (T value) { | 703 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 704 // checked mode. http://dartbug.com/7733 |
| 705 (/*T*/ value) { |
| 680 _runUserCode( | 706 _runUserCode( |
| 681 () => true == test(value), | 707 () => true == test(value), |
| 682 (bool isMatch) { | 708 (bool isMatch) { |
| 683 if (isMatch) { | 709 if (isMatch) { |
| 684 foundResult = true; | 710 foundResult = true; |
| 685 result = value; | 711 result = value; |
| 686 } | 712 } |
| 687 }, | 713 }, |
| 688 _cancelAndError(subscription, future) | 714 _cancelAndError(subscription, future) |
| 689 ); | 715 ); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 710 * | 736 * |
| 711 * Like [lastMatch], except that it is an error if more than one | 737 * Like [lastMatch], except that it is an error if more than one |
| 712 * matching element occurs in the stream. | 738 * matching element occurs in the stream. |
| 713 */ | 739 */ |
| 714 Future<T> singleMatching(bool test(T value)) { | 740 Future<T> singleMatching(bool test(T value)) { |
| 715 _FutureImpl<T> future = new _FutureImpl<T>(); | 741 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 716 T result = null; | 742 T result = null; |
| 717 bool foundResult = false; | 743 bool foundResult = false; |
| 718 StreamSubscription subscription; | 744 StreamSubscription subscription; |
| 719 subscription = this.listen( | 745 subscription = this.listen( |
| 720 (T value) { | 746 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 747 // checked mode. http://dartbug.com/7733 |
| 748 (/*T*/ value) { |
| 721 _runUserCode( | 749 _runUserCode( |
| 722 () => true == test(value), | 750 () => true == test(value), |
| 723 (bool isMatch) { | 751 (bool isMatch) { |
| 724 if (isMatch) { | 752 if (isMatch) { |
| 725 if (foundResult) { | 753 if (foundResult) { |
| 726 subscription.cancel(); | 754 subscription.cancel(); |
| 727 future._setError(new AsyncError( | 755 future._setError(new AsyncError( |
| 728 new StateError('Multiple matches for "single"'))); | 756 new StateError('Multiple matches for "single"'))); |
| 729 return; | 757 return; |
| 730 } | 758 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 754 * If an error event occurs, the future will end with this error. | 782 * If an error event occurs, the future will end with this error. |
| 755 * | 783 * |
| 756 * If this stream provides fewer than [index] elements before closing, | 784 * If this stream provides fewer than [index] elements before closing, |
| 757 * an error is reported. | 785 * an error is reported. |
| 758 */ | 786 */ |
| 759 Future<T> elementAt(int index) { | 787 Future<T> elementAt(int index) { |
| 760 if (index is! int || index < 0) throw new ArgumentError(index); | 788 if (index is! int || index < 0) throw new ArgumentError(index); |
| 761 _FutureImpl<T> future = new _FutureImpl<T>(); | 789 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 762 StreamSubscription subscription; | 790 StreamSubscription subscription; |
| 763 subscription = this.listen( | 791 subscription = this.listen( |
| 764 (T value) { | 792 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 793 // checked mode. http://dartbug.com/7733 |
| 794 (/*T*/ value) { |
| 765 if (index == 0) { | 795 if (index == 0) { |
| 766 future._setValue(value); | 796 future._setValue(value); |
| 767 subscription.cancel(); | 797 subscription.cancel(); |
| 768 return; | 798 return; |
| 769 } | 799 } |
| 770 index -= 1; | 800 index -= 1; |
| 771 }, | 801 }, |
| 772 onError: future._setError, | 802 onError: future._setError, |
| 773 onDone: () { | 803 onDone: () { |
| 774 future._setError(new AsyncError( | 804 future._setError(new AsyncError( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 */ | 927 */ |
| 898 factory StreamTransformer.from({ | 928 factory StreamTransformer.from({ |
| 899 void onData(S data, StreamSink<T> sink), | 929 void onData(S data, StreamSink<T> sink), |
| 900 void onError(AsyncError error, StreamSink<T> sink), | 930 void onError(AsyncError error, StreamSink<T> sink), |
| 901 void onDone(StreamSink<T> sink)}) { | 931 void onDone(StreamSink<T> sink)}) { |
| 902 return new _StreamTransformerImpl<S, T>(onData, onError, onDone); | 932 return new _StreamTransformerImpl<S, T>(onData, onError, onDone); |
| 903 } | 933 } |
| 904 | 934 |
| 905 Stream<T> bind(Stream<S> stream); | 935 Stream<T> bind(Stream<S> stream); |
| 906 } | 936 } |
| OLD | NEW |