Change proxies lifecycle

This commit is contained in:
problematicconsumer
2023-09-10 20:27:07 +03:30
parent dedccdd772
commit cd37f5124a
6 changed files with 37 additions and 16 deletions

View File

@@ -0,0 +1,23 @@
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();
});
}
}