subscription_tracker 1.0.1 copy "subscription_tracker: ^1.0.1" to clipboard
subscription_tracker: ^1.0.1 copied to clipboard

Subscription tracker for Streams.

Subscription Tracker #

pub package

Effortless subscription management for Dart Streams. Track, cancel, and simplify your asynchronous code.

Features #

  • Centralized Subscription Tracking: Keep all your Stream subscriptions organized within a SubscriptionTracker instance.
  • Bulk Cancellation: Cleanly unsubscribe from all tracked subscriptions with a single cancelAll() call.
  • Stream Extension: Leverage the listenTracked extension method for seamless integration with existing Stream usage.
  • Lightweight: Minimal overhead, ensuring your application remains performant.

Installation #

Add subscription_tracker to your pubspec.yaml:

dependencies:
  subscription_tracker: ^latest_version

Then, run dart pub get.

Usage #

import 'package:subscription_tracker/subscription_tracker.dart';

void main() {
  final tracker = SubscriptionTracker();

  final subscription1 = someStream.listenTracked(tracker, (data) {
    // Handle stream data
  });

  final subscription2 = anotherStream.listenTracked(tracker, (data) {
    // Handle stream data
  });

  // ... Later in your code, when you want to cancel all subscriptions:
  tracker.cancelAll(); 
}

Why Subscription Tracker? #

  • Prevent Memory Leaks: Avoid unintentional subscriptions lingering in memory.
  • Code Clarity: Centralize subscription management for cleaner, more maintainable code.
  • Simplified Cleanup: Ensure resources are released correctly when components are disposed of.

Contributing #

Contributions are welcome! Feel free to open issues or submit pull requests.

License #

BSD Clause 3

1
likes
125
points
30
downloads

Publisher

verified publishermolfars.dev

Weekly Downloads

Subscription tracker for Streams.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on subscription_tracker