debounce method

Future debounce(
  1. Function func
)

Implementation

Future<dynamic> debounce(Function func) async {
  if (this._waiter?.isActive ?? false) {
    this._waiter?.cancel();
    this._resultSC.sink.add(null);
  }
  this._isReady = false;
  this._stateSC.sink.add(false);
  this._waiter = Timer(this._duration, () {
    this._isReady = true;
    this._stateSC.sink.add(true);
    this._resultSC.sink.add(Function.apply(func, []));
  });
  return this._resultSC.stream.first;
}