stream_event_guard 0.1.0 copy "stream_event_guard: ^0.1.0" to clipboard
stream_event_guard: ^0.1.0 copied to clipboard

Keyed duplicate suppression and cooldown control for synchronous and asynchronous Dart events.

example/stream_event_guard_example.dart

import 'dart:async';

import 'package:stream_event_guard/stream_event_guard.dart';

Future<void> main() async {
  final scanner = StreamController<String>();
  final guard = EventGuard<String>(cooldown: const Duration(seconds: 2));

  scanner.stream.listen((code) {
    guard.run(
      key: code,
      action: () async {
        await _processCode(code);
      },
    );
  });

  scanner
    ..add('ABC123')
    ..add('ABC123')
    ..add('ABC123')
    ..add('XYZ999');

  await scanner.close();
}

Future<void> _processCode(String code) async {
  await Future<void>.delayed(const Duration(milliseconds: 100));
  print('Processed: $code');
}
3
likes
160
points
145
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Keyed duplicate suppression and cooldown control for synchronous and asynchronous Dart events.

Repository (GitHub)
View/report issues

Topics

#async #concurrency #deduplication #events

License

MIT (license)

More

Packages that depend on stream_event_guard