LighthouseApp/lib/utils/riverpod_utils.dart
speakeloudest 75d4c48e41
Some checks failed
Build Windows / build (push) Has been cancelled
feat: 源码提交
2025-10-19 23:30:54 -07:00

24 lines
414 B
Dart
Executable File

import 'dart:async';
import 'package:hooks_riverpod/hooks_riverpod.dart';
extension RefLifeCycle<T> on AutoDisposeRef<T> {
void disposeDelay(Duration duration) {
final link = keepAlive();
Timer? timer;
onCancel(() {
timer?.cancel();
timer = Timer(duration, link.close);
});
onDispose(() {
timer?.cancel();
});
onResume(() {
timer?.cancel();
});
}
}