import 'dart:async';

class ResponseChecker<T> {
  final T _responser;
  late int _time;
  Timer? _timer;
  final void Function(T) _notResponseListener;

  T get responser => _responser;

  ResponseChecker(this._responser, this._time, this._notResponseListener) {
    _startTimer();
  }

  ResponseChecker.second(this._responser, int time, this._notResponseListener) {
    _time = time * 1000;
    _startTimer();
  }

  void _startTimer() {
    _timer = Timer(Duration(milliseconds: _time), () {
      _notResponseListener(_responser);
    });
  }

  T responded() {
    _timer?.cancel();
    _timer = null;
    return _responser;
  }
}
