Skip to content

Commit

Permalink
improve: memory management
Browse files Browse the repository at this point in the history
improve: remove performance cost of debounce on non-debounce instances.
  • Loading branch information
ali77gh committed Apr 6, 2023
1 parent 3d9240d commit 8719e19
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/src/telescope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ class Telescope<T> {
void calAndUpdate() {
isCalculating?.value = true;
int dh = getDependenciesHash();
Future.delayed(debounceTime, () {
if (debounceTime != Duration.zero) {
int cdh = getDependenciesHash();
if (dh != cdh) return;
}
void inner(){
cal().then((value) {
if (enableCaching) {
hashmap[dh] = value;
if (cacheExpireTime != null) {
var expTime = DateTime.now().add(cacheExpireTime);
expireTimeMap[dh] = expTime;
Future.delayed(cacheExpireTime, (){
expireTimeMap.remove(dh);
});
}
}
int cdh = getDependenciesHash();
Expand All @@ -107,7 +106,16 @@ class Telescope<T> {
isCalculating?.value = false;
notifyAll();
});
});
}
if (debounceTime != Duration.zero) {
Future.delayed(debounceTime, () {
int cdh = getDependenciesHash();
if (dh != cdh) return;
inner();
});
}else{
inner();
}
}

calAndUpdate();
Expand Down

0 comments on commit 8719e19

Please sign in to comment.