disposebag

Creator: coderz1093

Last updated:

0 purchases

disposebag Image
disposebag Images

Languages

Categories

Add to Cart

Description:

disposebag

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








A package helps to cancel StreamSubscriptions and close Sinks.
Medium article #
How to easily cancel streams in Flutter
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");
}
copied to clipboard
API #
1. Add, addAll #
Future<bool> DisposeBag.add(StreamSubscription);
Future<bool> DisposeBag.add(Sink);
Future<void> DisposeBag.addAll(Iterable<StreamSubscription>);
Future<void> DisposeBag.addAll(Iterable<Sink>);

// extension methods
Future<bool> StreamSubscription.disposedBy(DisposeBag);
Future<bool> Sink.disposedBy(DisposeBag);
Future<void> Iterable<StreamSubscription>.disposedBy(DisposeBag);
Future<void> Iterable<Sink>.disposedBy(DisposeBag);
copied to clipboard
2. Delete (removes but does not dispose) #
bool delete(StreamSubscription);
bool delete(Sink);
copied to clipboard
3. Remove (removes and disposes) #
Future<bool> remove(StreamSubscription);
Future<bool> remove(Sink);
copied to clipboard
4. Clear, dispose #
Future<void> clear();
Future<void> dispose();
copied to clipboard
Features and bugs #
Please file feature requests and bugs at the issue tracker.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.