-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert refTimeout to keepAliveDuration extension
- Loading branch information
1 parent
8b70a92
commit c717de2
Showing
5 changed files
with
35 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/pub/pagination_dart/lib/src/keep_alive_duration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:riverpod/riverpod.dart'; | ||
|
||
extension KeepAliveDurationExtension<T> on AutoDisposeRef<T> { | ||
/// Keeps a [Ref] alive for a given [duration]. | ||
/// | ||
/// Any inflight requests will need to be cancelled separately. | ||
void keepAliveDuration([Duration duration = const Duration(seconds: 30)]) { | ||
// When a provider is no-longer used, keep it in the cache for some time | ||
final link = keepAlive(); | ||
Timer? timer; | ||
|
||
onDispose(() { | ||
timer?.cancel(); | ||
}); | ||
|
||
onCancel(() { | ||
timer = Timer(duration, link.close); | ||
}); | ||
|
||
onResume(() { | ||
timer?.cancel(); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.