Skip to content

Commit

Permalink
convert refTimeout to keepAliveDuration extension
Browse files Browse the repository at this point in the history
  • Loading branch information
getBoolean committed Apr 13, 2024
1 parent 8b70a92 commit c717de2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
7 changes: 4 additions & 3 deletions packages/pub/pagination/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ PaginatedView(
Implement a `PaginatedResult` for your API response. This result can then be used
anywhere a `PaginatedResult` is expected, such as with `PaginatedView`.

### Ref Timeout
### Keep Alive Duration

Keeps a `Provider` alive for a given `Duration`.
Keeps an `autoDispose Provider` alive for a given `Duration` even if
the provider is no longer used.

```dart
applyRefTimeout<T>(
keepAliveDuration<T>(
AutoDisposeRef<T> ref, [
Duration duration = const Duration(seconds: 30),
])
Expand Down
7 changes: 4 additions & 3 deletions packages/pub/pagination_dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class MyPaginatedResult<T> with MyPaginatedResultMappable<T>
}
```

### Ref Timeout
### Keep Alive Duration

Keeps a `Provider` alive for a given `Duration`.
Keeps an `autoDispose Provider` alive for a given `Duration` even if
the provider is no longer used.

```dart
applyRefTimeout<T>(
keepAliveDuration<T>(
AutoDisposeRef<T> ref, [
Duration duration = const Duration(seconds: 30),
])
Expand Down
2 changes: 1 addition & 1 deletion packages/pub/pagination_dart/lib/pagination_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
library;

export 'src/paginated_result.dart';
export 'src/ref_timeout.dart';
export 'src/keep_alive_duration.dart';
26 changes: 26 additions & 0 deletions packages/pub/pagination_dart/lib/src/keep_alive_duration.dart
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();
});
}
}
27 changes: 0 additions & 27 deletions packages/pub/pagination_dart/lib/src/ref_timeout.dart

This file was deleted.

0 comments on commit c717de2

Please sign in to comment.