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

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

Issue 25354003: Redo StreamTransformers so they work with Stack traces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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_impl.dart ('k') | sdk/lib/async/stream_transformers.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 * Utility function to attach a stack trace to an [error] if it doesn't have 8 * Utility function to attach a stack trace to an [error] if it doesn't have
9 * one already. 9 * one already.
10 */ 10 */
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 sink._addError(_asyncError(e, s), s); 393 sink._addError(_asyncError(e, s), s);
394 return null; 394 return null;
395 } 395 }
396 if (!isEqual) { 396 if (!isEqual) {
397 sink._add(inputEvent); 397 sink._add(inputEvent);
398 _previous = inputEvent; 398 _previous = inputEvent;
399 } 399 }
400 } 400 }
401 } 401 }
402 } 402 }
403
404 // Stream transformations and event transformations.
405
406 typedef void _TransformDataHandler<S, T>(S data, EventSink<T> sink);
407 typedef void _TransformErrorHandler<T>(Object error, EventSink<T> sink);
408 typedef void _TransformDoneHandler<T>(EventSink<T> sink);
409
410 /** Default data handler forwards all data. */
411 void _defaultHandleData(var data, EventSink sink) {
412 sink.add(data);
413 }
414
415 /** Default error handler forwards all errors. */
416 void _defaultHandleError(error, EventSink sink) {
417 sink.addError(error);
418 }
419
420 /** Default done handler forwards done. */
421 void _defaultHandleDone(EventSink sink) {
422 sink.close();
423 }
424
425
426 /**
427 * A [StreamTransformer] that modifies stream events.
428 *
429 * This class is used by [StreamTransformer]'s factory constructor.
430 * It is actually an [StreamEventTransformer] where the functions used to
431 * modify the events are passed as constructor arguments.
432 *
433 * If an argument is omitted, it acts as the default method from
434 * [StreamEventTransformer].
435 */
436 class _StreamTransformerImpl<S, T> extends StreamEventTransformer<S, T> {
437 final _TransformDataHandler<S, T> _handleData;
438 final _TransformErrorHandler<T> _handleError;
439 final _TransformDoneHandler<T> _handleDone;
440
441 _StreamTransformerImpl(void handleData(S data, EventSink<T> sink),
442 void handleError(data, EventSink<T> sink),
443 void handleDone(EventSink<T> sink))
444 : this._handleData = (handleData == null ? _defaultHandleData
445 : handleData),
446 this._handleError = (handleError == null ? _defaultHandleError
447 : handleError),
448 this._handleDone = (handleDone == null ? _defaultHandleDone
449 : handleDone);
450
451 void handleData(S data, EventSink<T> sink) {
452 _handleData(data, sink);
453 }
454
455 void handleError(error, EventSink<T> sink) {
456 _handleError(error, sink);
457 }
458
459 void handleDone(EventSink<T> sink) {
460 _handleDone(sink);
461 }
462 }
463
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/stream_transformers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698