RxDispose.dart 504 Bytes
Newer Older
林生雨's avatar
林生雨 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * @author lsy
 * @date   2020/5/22
 **/

import 'dart:async';

class RxDispose {
  List<StreamSubscription> rx;

  RxDispose() {
    rx = List();
  }

  void addDispose(StreamSubscription streamSubscription) {
    rx.add(streamSubscription);
  }

  void dispose() {
    rx.forEach((element) {
      element.cancel();
    });
  }
}

extension StreamSubscriptionExt on StreamSubscription {
  StreamSubscription addToDispose(RxDispose rxDispose) {
    rxDispose.addDispose(this);
    return this;
  }
}