- Dart: Add explicit Future<void> return type to send() method - Dart: Improve onDisconnected() logic with proper isAlive handling and heartbeat response - Go: Introduce baseClient generic base class for shared client logic - Go: Refactor TcpClient and WsClient to embed baseClient instead of embedding Communicator - Remove duplicate heartbeat and disconnect handling code across client implementations - Clean up unused imports (time package)
31 lines
637 B
Dart
31 lines
637 B
Dart
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;
|
|
}
|
|
}
|