Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: sdk/lib/async/stream_controller.dart

Issue 555153002: Add error-intercept for Completer.completeError and StreamController.addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Intercept all errors thrown by unregistered callbacks. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/async/stream_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 void add(T value) { 408 void add(T value) {
409 if (!_mayAddEvent) throw _badEventState(); 409 if (!_mayAddEvent) throw _badEventState();
410 _add(value); 410 _add(value);
411 } 411 }
412 412
413 /** 413 /**
414 * Send or enqueue an error event. 414 * Send or enqueue an error event.
415 */ 415 */
416 void addError(Object error, [StackTrace stackTrace]) { 416 void addError(Object error, [StackTrace stackTrace]) {
417 if (!_mayAddEvent) throw _badEventState(); 417 if (!_mayAddEvent) throw _badEventState();
418 AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
419 if (replacement != null) {
420 error = replacement.error;
421 stackTrace = replacement.stackTrace;
422 }
418 _addError(error, stackTrace); 423 _addError(error, stackTrace);
419 } 424 }
420 425
421 /** 426 /**
422 * Closes this controller and sends a done event on the stream. 427 * Closes this controller and sends a done event on the stream.
423 * 428 *
424 * The first time a controller is closed, a "done" event is added to its 429 * The first time a controller is closed, a "done" event is added to its
425 * stream. 430 * stream.
426 * 431 *
427 * You are allowed to close the controller more than once, but only the first 432 * You are allowed to close the controller more than once, but only the first
428 * call has any effect. 433 * call has any effect.
429 * 434 *
430 * After closing, no further events may be added using [add] or [addError]. 435 * After closing, no further events may be added using [add] or [addError].
431 * 436 *
432 * The returned future is completed when the done event has been delivered. 437 * The returned future is completed when the done event has been delivered.
433 */ 438 */
434 Future close() { 439 Future close() {
435 if (isClosed) { 440 if (isClosed) {
436 return _ensureDoneFuture(); 441 return _ensureDoneFuture();
437 } 442 }
438 if (!_mayAddEvent) throw _badEventState(); 443 if (!_mayAddEvent) throw _badEventState();
444 _closeUnchecked();
445 return _ensureDoneFuture();
446 }
447
448 void _closeUnchecked() {
439 _state |= _STATE_CLOSED; 449 _state |= _STATE_CLOSED;
440 if (hasListener) { 450 if (hasListener) {
441 _sendDone(); 451 _sendDone();
442 } else if (_isInitialState) { 452 } else if (_isInitialState) {
443 _ensurePendingEvents().add(const _DelayedDone()); 453 _ensurePendingEvents().add(const _DelayedDone());
444 } 454 }
445 return _ensureDoneFuture();
446 } 455 }
447 456
448 // EventSink interface. Used by the [addStream] events. 457 // EventSink interface. Used by the [addStream] events.
449 458
450 // Add data event, used both by the [addStream] events and by [add]. 459 // Add data event, used both by the [addStream] events and by [add].
451 void _add(T value) { 460 void _add(T value) {
452 if (hasListener) { 461 if (hasListener) {
453 _sendData(value); 462 _sendData(value);
454 } else if (_isInitialState) { 463 } else if (_isInitialState) {
455 _ensurePendingEvents().add(new _DelayedData<T>(value)); 464 _ensurePendingEvents().add(new _DelayedData<T>(value));
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 _StreamControllerAddStreamState(_StreamController controller, 791 _StreamControllerAddStreamState(_StreamController controller,
783 this.varData, 792 this.varData,
784 Stream source, 793 Stream source,
785 bool cancelOnError) 794 bool cancelOnError)
786 : super(controller, source, cancelOnError) { 795 : super(controller, source, cancelOnError) {
787 if (controller.isPaused) { 796 if (controller.isPaused) {
788 addSubscription.pause(); 797 addSubscription.pause();
789 } 798 }
790 } 799 }
791 } 800 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/async/stream_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698