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

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

Issue 2444363004: Handle the case of Stream.take(0) better. (Closed)
Patch Set: Created 4 years, 1 month 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
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 /** Runs user code and takes actions depending on success or failure. */ 7 /** Runs user code and takes actions depending on success or failure. */
8 _runUserCode(userCode(), 8 _runUserCode(userCode(),
9 onSuccess(value), 9 onSuccess(value),
10 onError(error, StackTrace stackTrace)) { 10 onError(error, StackTrace stackTrace)) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // This test is done early to avoid handling an async error 319 // This test is done early to avoid handling an async error
320 // in the _handleData method. 320 // in the _handleData method.
321 if (count is! int) throw new ArgumentError(count); 321 if (count is! int) throw new ArgumentError(count);
322 } 322 }
323 323
324 StreamSubscription<T> _createSubscription( 324 StreamSubscription<T> _createSubscription(
325 void onData(T data), 325 void onData(T data),
326 Function onError, 326 Function onError,
327 void onDone(), 327 void onDone(),
328 bool cancelOnError) { 328 bool cancelOnError) {
329 if (_count == 0) {
330 return new _DoneSubscription<T>(onDone);
331 }
329 return new _StateStreamSubscription<T>( 332 return new _StateStreamSubscription<T>(
330 this, onData, onError, onDone, cancelOnError, _count); 333 this, onData, onError, onDone, cancelOnError, _count);
331 } 334 }
332 335
333 void _handleData(T inputEvent, _EventSink<T> sink) { 336 void _handleData(T inputEvent, _EventSink<T> sink) {
334 _StateStreamSubscription<T> subscription = sink; 337 _StateStreamSubscription<T> subscription = sink;
335 int count = subscription._count; 338 int count = subscription._count;
336 if (count > 0) { 339 if (count > 0) {
337 sink._add(inputEvent); 340 sink._add(inputEvent);
338 count -= 1; 341 count -= 1;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 _addErrorWithReplacement(sink, e, s); 489 _addErrorWithReplacement(sink, e, s);
487 return null; 490 return null;
488 } 491 }
489 if (!isEqual) { 492 if (!isEqual) {
490 sink._add(inputEvent); 493 sink._add(inputEvent);
491 _previous = inputEvent; 494 _previous = inputEvent;
492 } 495 }
493 } 496 }
494 } 497 }
495 } 498 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/async/stream_take_test.dart » ('j') | tests/lib/async/stream_take_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698