pausable_behavior_subject 0.2.0 copy "pausable_behavior_subject: ^0.2.0" to clipboard
pausable_behavior_subject: ^0.2.0 copied to clipboard

A package that provides a way to pause and resume event emissions for streams that do not natively support it.

example/main.dart

import 'dart:async';

import 'package:pausable_behavior_subject/pausable_behavior_subject.dart';

Future<void> main() async {
  final controller = StreamController<int>.broadcast();
  final subject = PausableBehaviorSubject<int>(controller.stream);

  final receivedValues = <int>[];
  subject.stream.listen(receivedValues.add);

  controller.add(1);
  await Future.delayed(Duration.zero);

  await subject.pause();

  controller.add(2);
  controller.add(3);
  await Future.delayed(Duration.zero);

  // ignore: avoid_print
  print(receivedValues.toString()); // Should print: [1]

  // Closes the subject as well
  await controller.close();

  // In case you don't have control over the source stream, you can simply dispose of the subject only
  await subject.dispose();
}
1
likes
160
points
8
downloads

Publisher

verified publishernorbertcsorgo.me

Weekly Downloads

A package that provides a way to pause and resume event emissions for streams that do not natively support it.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, rxdart

More

Packages that depend on pausable_behavior_subject