disposebag 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

disposebag #

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

Pub codecov Build Status

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 bag.dispose();
  
  print("Bag disposed. It's all good");
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.1.1 - Jan 22, 2020 #

  • Fix collection version

1.1.0 - Jan 22, 2020 #

  • Add logger that logs disposed resources
  • Minors update
  • Upgrade min sdk to 2.6.0

1.0.0+1 - Nov 9, 2019 #

  • Minors update

1.0.0 - Aug 14, 2019 #

  • Minors update
  • Add tests

0.0.9 #

  • Initial version, created by Stagehand

example/disposebag_example.dart

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

List<dynamic> get _disposables {
  final controllers = <StreamController>[
    StreamController<int>()..add(1)..add(2),
    StreamController<int>(sync: true)..add(3)..add(4),
    StreamController<int>.broadcast()..add(5)..add(6),
    StreamController<String>.broadcast(sync: true)..add('7')..add('8'),
  ];
  final subscriptions = <StreamSubscription>[
    Stream.periodic(const Duration(milliseconds: 100), (i) => i)
        .listen((data) => print('[1] $data')),
    Stream.periodic(const Duration(milliseconds: 10), (i) => i)
        .listen((data) => print('[2] $data')),
    for (int i = 0; i < controllers.length; i++)
      controllers[i].stream.listen((data) => print('[${i + 3}] $data')),
  ];
  return [...controllers, ...subscriptions];
}

void main() async {
  final bag = DisposeBag(_disposables);
  await Future.delayed(const Duration(seconds: 2));
  await bag.dispose();

  await Future.delayed(const Duration(seconds: 2));
  print("Bag disposed. It's all good");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  disposebag: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:disposebag/disposebag.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jan 22, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
collection ^1.14.11 1.14.12
meta ^1.1.6 1.1.8
Dev dependencies
pedantic ^1.9.0
test ^1.0.0