bouncer 1.0.2 copy "bouncer: ^1.0.2" to clipboard
bouncer: ^1.0.2 copied to clipboard

Bouncer debounces actions and makes sure any long-running requests will be ignored.

Build Status pub package codecov

bouncer #

Bouncer debounces actions and makes sure any outdated answers will be ignored.

Problem statement #

When user actions lead to starting several concurrent requests to some slow resource, there can be 2 problems:

  1. exhausting of the resource
  2. answers coming in random order

This library aims to solve both problems.

See example for reference.

Usage #

instead of

  var response = await _longRunningRequest(parameters)
  _responseHandler(response);

let's debounce:

  _debounceSubscription = TimerBouncer(Duration(milliseconds: 200)).debounce(
    request: () => _longRunningRequest(parameters),
    responseHandler: _responseHandler,
    oldSubscription: _debounceSubscription,
  );

don't forget to dispose _debounceSubscription when it's no longer in use.

  @override
  dispose() {
    _debounceSubscription?.cancel();
    super.dispose();
  }
4
likes
140
pub points
47%
popularity

Publisher

verified publisheractvst.com

Bouncer debounces actions and makes sure any long-running requests will be ignored.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on bouncer