Line data Source code
1 : // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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. 4 : 5 : import 'dart:async'; 6 : 7 : class TypeSafeStreamSubscription<T> implements StreamSubscription<T> { 8 : final StreamSubscription _subscription; 9 : 10 0 : @override 11 0 : bool get isPaused => _subscription.isPaused; 12 : 13 0 : TypeSafeStreamSubscription(this._subscription); 14 : 15 0 : @override 16 : void onData(void Function(T)? handleData) { 17 0 : if (handleData == null) return _subscription.onData(null); 18 0 : _subscription.onData((data) => handleData(data as T)); 19 : } 20 : 21 0 : @override 22 : void onError(Function? handleError) { 23 0 : _subscription.onError(handleError); 24 : } 25 : 26 0 : @override 27 : void onDone(void Function()? handleDone) { 28 0 : _subscription.onDone(handleDone); 29 : } 30 : 31 0 : @override 32 : void pause([Future? resumeFuture]) { 33 0 : _subscription.pause(resumeFuture); 34 : } 35 : 36 0 : @override 37 : void resume() { 38 0 : _subscription.resume(); 39 : } 40 : 41 0 : @override 42 0 : Future cancel() => _subscription.cancel(); 43 : 44 0 : @override 45 : Future<E> asFuture<E>([E? futureValue]) => 46 0 : _subscription.asFuture(futureValue); 47 : }