Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunPrakashG committed Jul 6, 2024
1 parent d64a81d commit 1f1c740
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/src/ever_cache_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ final class EverCache<T> extends ILockable<T> {
_scheduleInvalidation();
}
}

/// A function that asynchronously fetches the value to be cached.
final Future<T> Function() _fetch;

/// An optional function that returns a placeholder value until the actual value is fetched.
final T Function()? placeholder;

/// An optional function that allows to define custom disposing logic for the object.
final void Function(T? value)? disposer;

Expand All @@ -50,7 +53,7 @@ final class EverCache<T> extends ILockable<T> {

Timer? _timer;

final bool _isComputing = false;
bool _isComputing = false;

bool _isDisposed = false;

Expand All @@ -76,7 +79,7 @@ final class EverCache<T> extends ILockable<T> {

/// Indicates whether a timer for invalidation (based on TTL) is scheduled.
bool get scheduled => _timer != null;

/// The cached value of type [T].
///
/// Throws an [EverStateException] if the value has been disposed or is being evaluated.
Expand Down Expand Up @@ -135,17 +138,15 @@ final class EverCache<T> extends ILockable<T> {
}

_value = await guard(
() async, => _fetch(),
onError: (e, s) {
_isComputing = false;
events?.onError?.call(e, s);
},
() async => _fetch(),
onError: events?.onError?.call,
onStart: () {
_isComputing = true;
events?.onComputing?.call();
final value = await _fetch();
},
onEnd: () {
_isComputing = false;
events?.onComputed?.call();
return value;
},
);

Expand Down Expand Up @@ -173,7 +174,7 @@ final class EverCache<T> extends ILockable<T> {
}

return backgrounded(
() async, => _fetch(),
() async => _fetch(),
then: (object) => _value = object,
onStart: () {
_isComputing = true;
Expand Down

0 comments on commit 1f1c740

Please sign in to comment.