| 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 // States shared by single/multi stream implementations. | 7 // States shared by single/multi stream implementations. |
| 8 | 8 |
| 9 /// Initial and default state where the stream can receive and send events. | 9 /// Initial and default state where the stream can receive and send events. |
| 10 const int _STREAM_OPEN = 0; | 10 const int _STREAM_OPEN = 0; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 330 |
| 331 /** | 331 /** |
| 332 * Send a data event directly to each subscriber. | 332 * Send a data event directly to each subscriber. |
| 333 */ | 333 */ |
| 334 _sendData(T value) { | 334 _sendData(T value) { |
| 335 assert(!_isPaused); | 335 assert(!_isPaused); |
| 336 assert(!_isComplete); | 336 assert(!_isComplete); |
| 337 _forEachSubscriber((subscriber) { | 337 _forEachSubscriber((subscriber) { |
| 338 try { | 338 try { |
| 339 subscriber._sendData(value); | 339 subscriber._sendData(value); |
| 340 } on AsyncError catch (e) { |
| 341 e.throwDelayed(); |
| 340 } catch (e, s) { | 342 } catch (e, s) { |
| 341 new AsyncError(e, s).throwDelayed(); | 343 new AsyncError(e, s).throwDelayed(); |
| 342 } | 344 } |
| 343 }); | 345 }); |
| 344 } | 346 } |
| 345 | 347 |
| 346 /** | 348 /** |
| 347 * Sends an error event directly to each subscriber. | 349 * Sends an error event directly to each subscriber. |
| 348 */ | 350 */ |
| 349 void _sendError(AsyncError error) { | 351 void _sendError(AsyncError error) { |
| 350 assert(!_isPaused); | 352 assert(!_isPaused); |
| 351 assert(!_isComplete); | 353 assert(!_isComplete); |
| 352 _forEachSubscriber((subscriber) { | 354 _forEachSubscriber((subscriber) { |
| 353 try { | 355 try { |
| 354 subscriber._sendError(error); | 356 subscriber._sendError(error); |
| 357 } on AsyncError catch (e) { |
| 358 e.throwDelayed(); |
| 355 } catch (e, s) { | 359 } catch (e, s) { |
| 356 new AsyncError.withCause(e, s, error).throwDelayed(); | 360 new AsyncError.withCause(e, s, error).throwDelayed(); |
| 357 } | 361 } |
| 358 }); | 362 }); |
| 359 } | 363 } |
| 360 | 364 |
| 361 /** | 365 /** |
| 362 * Sends the "done" message directly to each subscriber. | 366 * Sends the "done" message directly to each subscriber. |
| 363 * This automatically stops further subscription and | 367 * This automatically stops further subscription and |
| 364 * unsubscribes all subscribers. | 368 * unsubscribes all subscribers. |
| 365 */ | 369 */ |
| 366 void _sendDone() { | 370 void _sendDone() { |
| 367 assert(!_isPaused); | 371 assert(!_isPaused); |
| 368 assert(_isClosed); | 372 assert(_isClosed); |
| 369 _setComplete(); | 373 _setComplete(); |
| 370 if (!_hasSubscribers) return; | 374 if (!_hasSubscribers) return; |
| 371 _forEachSubscriber((subscriber) { | 375 _forEachSubscriber((subscriber) { |
| 372 _cancel(subscriber); | 376 _cancel(subscriber); |
| 373 try { | 377 try { |
| 374 subscriber._sendDone(); | 378 subscriber._sendDone(); |
| 379 } on AsyncError catch (e) { |
| 380 e.throwDelayed(); |
| 375 } catch (e, s) { | 381 } catch (e, s) { |
| 376 new AsyncError(e, s).throwDelayed(); | 382 new AsyncError(e, s).throwDelayed(); |
| 377 } | 383 } |
| 378 }); | 384 }); |
| 379 assert(!_hasSubscribers); | 385 assert(!_hasSubscribers); |
| 380 _onSubscriptionStateChange(); | 386 _onSubscriptionStateChange(); |
| 381 } | 387 } |
| 382 } | 388 } |
| 383 | 389 |
| 384 // ------------------------------------------------------------------- | 390 // ------------------------------------------------------------------- |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 if (_isComplete) { | 1086 if (_isComplete) { |
| 1081 throw new StateError("Subscription has been canceled."); | 1087 throw new StateError("Subscription has been canceled."); |
| 1082 } | 1088 } |
| 1083 if (_timer != null) { | 1089 if (_timer != null) { |
| 1084 _timer.cancel(); | 1090 _timer.cancel(); |
| 1085 _timer = null; | 1091 _timer = null; |
| 1086 } | 1092 } |
| 1087 _pauseCount = 0; | 1093 _pauseCount = 0; |
| 1088 } | 1094 } |
| 1089 } | 1095 } |
| OLD | NEW |