disposebag

Author: Petrus Nguyễn Thái Học

Dart CI Codacy Badge Pub codecov Build Status GitHub Style

A package to help disposing Streams and closing Sinks

Usage

A simple usage example:

import 'package:disposebag/disposebag.dart';
import 'dart:async';

main() async {
  final controllers = <StreamController>[];
  final subscriptions = <StreamSubscription>[];
 
  final bag = DisposeBag([...subscriptions, ...controllers]);

  await Stream.value(3).listen(null).disposedBy(bag);
  await StreamController<int>.broadcast().disposedBy(bag);
  await StreamController<int>.broadcast(sync: true).disposedBy(bag);

  await bag.dispose();
  print("Bag disposed. It's all good");
}

API

1. Add, addAll

Future<bool> DisposeBag.add(StreamSubscription);
Future<bool> DisposeBag.add(Sink);
Future<bool> DisposeBag.addAll(Iterable<StreamSubscription>);
Future<bool> DisposeBag.addAll(Iterable<Sink>);

// extension methods
Future<bool> StreamSubscription.disposedBy(DisposeBag);
Future<bool> Sink.disposedBy(DisposeBag);
Future<bool> Iterable<StreamSubscription>.disposedBy(DisposeBag);
Future<bool> Iterable<Sink>.disposedBy(DisposeBag);

2. Delete (removes but does not dispose)

Future<bool> delete(StreamSubscription);
Future<bool> delete(Sink);

3. Remove (removes and disposes)

Future<bool> remove(StreamSubscription);
Future<bool> remove(Sink);

4. Clear, dispose

Future<bool> clear();
Future<bool> dispose();

Features and bugs

Please file feature requests and bugs at the issue tracker.

Libraries

disposebag
Helper disposing Streams and closing Sinks [...]