| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'event_helper.dart'; | 8 import 'event_helper.dart'; |
| 9 | 9 |
| 10 _defaultData(x) {} | 10 _defaultData(x) {} |
| 11 _defaultError(e, [st]) {} | 11 _defaultError(e, [st]) {} |
| 12 _defaultDone() {} | 12 _defaultDone() {} |
| 13 | 13 |
| 14 /// Dummy StreamSubscription. | 14 /// Dummy StreamSubscription. |
| 15 class MyStreamSubscription<T> implements StreamSubscription<T> { | 15 class MyStreamSubscription<T> implements StreamSubscription<T> { |
| 16 final Stream stream; | 16 final Stream stream; |
| 17 final bool cancelOnError; | 17 final bool cancelOnError; |
| 18 Function handleData = null; | 18 Function handleData = null; |
| 19 Function handleError = null; | 19 Function handleError = null; |
| 20 Function handleDone = null; | 20 Function handleDone = null; |
| 21 | 21 |
| 22 MyStreamSubscription(this.stream, this.cancelOnError); | 22 MyStreamSubscription(this.stream, this.cancelOnError); |
| 23 | 23 |
| 24 void cancel() {} | 24 Future cancel() => null; |
| 25 void onData(void handleData(T data)) { | 25 void onData(void handleData(T data)) { |
| 26 this.handleData = handleData == null ? _defaultData: handleData; | 26 this.handleData = handleData == null ? _defaultData: handleData; |
| 27 } | 27 } |
| 28 void onError(Function handleError) { | 28 void onError(Function handleError) { |
| 29 this.handleError = handleError == null ? _defaultError: handleError; | 29 this.handleError = handleError == null ? _defaultError: handleError; |
| 30 } | 30 } |
| 31 void onDone(void handleDone()) { | 31 void onDone(void handleDone()) { |
| 32 this.handleDone = handleDone == null ? _defaultDone: handleDone; | 32 this.handleDone = handleDone == null ? _defaultDone: handleDone; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void pause([Future resumeSignal]) {} | 35 void pause([Future resumeSignal]) {} |
| 36 void resume() {} |
| 37 |
| 36 final isPaused = false; | 38 final isPaused = false; |
| 37 Future asFuture([var futureValue]) => null; | 39 Future asFuture([var futureValue]) => null; |
| 38 } | 40 } |
| 39 | 41 |
| 40 main() { | 42 main() { |
| 41 var transformer = new StreamTransformer<int, String> ( | 43 var transformer = new StreamTransformer<int, String> ( |
| 42 (stream, cancelOnError) => new MyStreamSubscription(stream, cancelOnError)); | 44 (stream, cancelOnError) => new MyStreamSubscription(stream, cancelOnError)); |
| 43 | 45 |
| 44 var controller = new StreamController(sync: true); | 46 var controller = new StreamController(sync: true); |
| 45 var stream = controller.stream; | 47 var stream = controller.stream; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 76 transformed = stream.transform(transformer); | 78 transformed = stream.transform(transformer); |
| 77 subscription = | 79 subscription = |
| 78 transformed.listen(null, onDone: handleDone, cancelOnError: true); | 80 transformed.listen(null, onDone: handleDone, cancelOnError: true); |
| 79 | 81 |
| 80 Expect.identical(stream, subscription.stream); | 82 Expect.identical(stream, subscription.stream); |
| 81 Expect.equals(true, subscription.cancelOnError); | 83 Expect.equals(true, subscription.cancelOnError); |
| 82 Expect.identical(_defaultData, subscription.handleData); | 84 Expect.identical(_defaultData, subscription.handleData); |
| 83 Expect.identical(_defaultError, subscription.handleError); | 85 Expect.identical(_defaultError, subscription.handleError); |
| 84 Expect.identical(handleDone, subscription.handleDone); | 86 Expect.identical(handleDone, subscription.handleDone); |
| 85 } | 87 } |
| OLD | NEW |