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

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: Fix two more tests. 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
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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 sink._addError(_asyncError(e, s), s); 397 sink._addError(_asyncError(e, s), s);
398 return null; 398 return null;
399 } 399 }
400 if (!isEqual) { 400 if (!isEqual) {
401 sink._add(inputEvent); 401 sink._add(inputEvent);
402 _previous = inputEvent; 402 _previous = inputEvent;
403 } 403 }
404 } 404 }
405 } 405 }
406 } 406 }
407
408 // Stream transformations and event transformations.
409
410 typedef void _TransformDataHandler<S, T>(S data, EventSink<T> sink);
411 typedef void _TransformErrorHandler<T>(Object error, EventSink<T> sink);
412 typedef void _TransformDoneHandler<T>(EventSink<T> sink);
413
414 /** Default data handler forwards all data. */
415 void _defaultHandleData(var data, EventSink sink) {
416 sink.add(data);
417 }
418
419 /** Default error handler forwards all errors. */
420 void _defaultHandleError(error, EventSink sink) {
421 sink.addError(error);
422 }
423
424 /** Default done handler forwards done. */
425 void _defaultHandleDone(EventSink sink) {
426 sink.close();
427 }
428
429
430 /**
431 * A [StreamTransformer] that modifies stream events.
432 *
433 * This class is used by [StreamTransformer]'s factory constructor.
434 * It is actually an [StreamEventTransformer] where the functions used to
435 * modify the events are passed as constructor arguments.
436 *
437 * If an argument is omitted, it acts as the default method from
438 * [StreamEventTransformer].
439 */
440 class _StreamTransformerImpl<S, T> extends StreamEventTransformer<S, T> {
441 final _TransformDataHandler<S, T> _handleData;
442 final _TransformErrorHandler<T> _handleError;
443 final _TransformDoneHandler<T> _handleDone;
444
445 _StreamTransformerImpl(void handleData(S data, EventSink<T> sink),
446 void handleError(data, EventSink<T> sink),
447 void handleDone(EventSink<T> sink))
448 : this._handleData = (handleData == null ? _defaultHandleData
449 : handleData),
450 this._handleError = (handleError == null ? _defaultHandleError
451 : handleError),
452 this._handleDone = (handleDone == null ? _defaultHandleDone
453 : handleDone);
454
455 void handleData(S data, EventSink<T> sink) {
456 _handleData(data, sink);
457 }
458
459 void handleError(error, EventSink<T> sink) {
460 _handleError(error, sink);
461 }
462
463 void handleDone(EventSink<T> sink) {
464 _handleDone(sink);
465 }
466 }
467
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698