| 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 // Controller for creating and adding events to a stream. | 8 // Controller for creating and adding events to a stream. |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 _StreamControllerAddStreamState addState = | 375 _StreamControllerAddStreamState addState = |
| 376 new _StreamControllerAddStreamState(this, | 376 new _StreamControllerAddStreamState(this, |
| 377 _varData, | 377 _varData, |
| 378 source, | 378 source, |
| 379 cancelOnError); | 379 cancelOnError); |
| 380 _varData = addState; | 380 _varData = addState; |
| 381 _state |= _STATE_ADDSTREAM; | 381 _state |= _STATE_ADDSTREAM; |
| 382 return addState.addStreamFuture; | 382 return addState.addStreamFuture; |
| 383 } | 383 } |
| 384 | 384 |
| 385 /** |
| 386 * Returns a future that is completed when the stream is done |
| 387 * processing events. |
| 388 * |
| 389 * This happens either when the done event has been sent, or if the |
| 390 * subscriber of a single-subscription stream is cancelled. |
| 391 */ |
| 385 Future get done => _ensureDoneFuture(); | 392 Future get done => _ensureDoneFuture(); |
| 386 | 393 |
| 387 Future _ensureDoneFuture() { | 394 Future _ensureDoneFuture() { |
| 388 if (_doneFuture == null) { | 395 if (_doneFuture == null) { |
| 389 _doneFuture = _isCanceled ? Future._nullFuture : new _Future(); | 396 _doneFuture = _isCanceled ? Future._nullFuture : new _Future(); |
| 390 } | 397 } |
| 391 return _doneFuture; | 398 return _doneFuture; |
| 392 } | 399 } |
| 393 | 400 |
| 394 /** | 401 /** |
| 395 * Send or enqueue a data event. | 402 * Send or enqueue a data event. |
| 396 */ | 403 */ |
| 397 void add(T value) { | 404 void add(T value) { |
| 398 if (!_mayAddEvent) throw _badEventState(); | 405 if (!_mayAddEvent) throw _badEventState(); |
| 399 _add(value); | 406 _add(value); |
| 400 } | 407 } |
| 401 | 408 |
| 402 /** | 409 /** |
| 403 * Send or enqueue an error event. | 410 * Send or enqueue an error event. |
| 404 */ | 411 */ |
| 405 void addError(Object error, [StackTrace stackTrace]) { | 412 void addError(Object error, [StackTrace stackTrace]) { |
| 406 if (!_mayAddEvent) throw _badEventState(); | 413 if (!_mayAddEvent) throw _badEventState(); |
| 407 _addError(error, stackTrace); | 414 _addError(error, stackTrace); |
| 408 } | 415 } |
| 409 | 416 |
| 410 /** | 417 /** |
| 411 * Closes this controller. | 418 * Closes this controller and sends a done event on the stream. |
| 412 * | 419 * |
| 413 * After closing, no further events may be added using [add] or [addError]. | 420 * The first time a controller is closed, a "done" event is added to its |
| 421 * stream. |
| 414 * | 422 * |
| 415 * You are allowed to close the controller more than once, but only the first | 423 * You are allowed to close the controller more than once, but only the first |
| 416 * call has any effect. | 424 * call has any effect. |
| 417 * | 425 * |
| 418 * The first time a controller is closed, a "done" event is sent to its | 426 * After closing, no further events may be added using [add] or [addError]. |
| 419 * stream. | 427 * |
| 428 * The returned future is completed when the done event has been delivered. |
| 420 */ | 429 */ |
| 421 Future close() { | 430 Future close() { |
| 422 if (isClosed) { | 431 if (isClosed) { |
| 423 return _ensureDoneFuture(); | 432 return _ensureDoneFuture(); |
| 424 } | 433 } |
| 425 if (!_mayAddEvent) throw _badEventState(); | 434 if (!_mayAddEvent) throw _badEventState(); |
| 426 _state |= _STATE_CLOSED; | 435 _state |= _STATE_CLOSED; |
| 427 if (hasListener) { | 436 if (hasListener) { |
| 428 _sendDone(); | 437 _sendDone(); |
| 429 } else if (_isInitialState) { | 438 } else if (_isInitialState) { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 _StreamControllerAddStreamState(_StreamController controller, | 768 _StreamControllerAddStreamState(_StreamController controller, |
| 760 this.varData, | 769 this.varData, |
| 761 Stream source, | 770 Stream source, |
| 762 bool cancelOnError) | 771 bool cancelOnError) |
| 763 : super(controller, source, cancelOnError) { | 772 : super(controller, source, cancelOnError) { |
| 764 if (controller.isPaused) { | 773 if (controller.isPaused) { |
| 765 addSubscription.pause(); | 774 addSubscription.pause(); |
| 766 } | 775 } |
| 767 } | 776 } |
| 768 } | 777 } |
| OLD | NEW |