disposebag 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

disposebag #

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

Pub 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 controller1 = StreamController<int>();
  final controller2 = StreamController<int>();
  final periodict = Stream.periodic(
    const Duration(milliseconds: 100),
    (int i) => i,
  );

  // Create dispose bag with diposables list
  final bag = DisposeBag([
    controller1,
    controller2,
  ]);

  // Add single subscription
  bag.add(periodict.listen(controller1.add));

  // Add many 
  bag.addAll([
    controller1.stream.listen(print),
    controller2.stream.listen(print),
  ]);

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

Features and bugs #

Please file feature requests and bugs at the issue tracker.

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';

main() async {
  final controller1 = StreamController<int>();
  final controller2 = StreamController<int>();
  final periodict = Stream.periodic(
    const Duration(milliseconds: 100),
    (int i) => i,
  );

  final bag = DisposeBag([
    controller1,
    controller2,
    periodict.listen(controller1.add),
    controller1.stream.listen((i) => print('Periodic $i')),
    controller2.stream.listen((i) => print('Controller2 $i')),
  ]);

  for (var i = 0; i < 100; i++) {
    controller2.add(i);
  }

  /// Delay to see output
  await Future.delayed(const Duration(seconds: 3));

  /// Dispose all stream subscriptions, close all stream controllers
  await bag.dispose();
  print("Bag disposed. It's all good");

  /// Controllers is closed
  print(controller1.isClosed);
  print(controller2.isClosed);

  /// Cannot add event to controllers
  try {
    controller1.add(1);
  } catch (e) {
    print(e);
  }
  try {
    controller2.add(3);
  } catch (e) {
    print(e);
  }

  /// Delay to see output
  await Future.delayed(const Duration(seconds: 2));
  print('Done');
}

Use this package as a library

1. Depend on it

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


dependencies:
  disposebag: ^1.0.0

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]
67
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
94
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Oct 23, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:disposebag/disposebag.dart.

Health suggestions

Format lib/disposebag.dart.

Run dartfmt to format lib/disposebag.dart.

Maintenance suggestions

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
meta >=1.1.1 <2.0.0 1.1.7
Dev dependencies
pedantic ^1.0.0
test ^1.0.0