Skip to content

Commit

Permalink
fix: timeoutmap warn
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed Mar 23, 2021
1 parent 3bd2dfb commit 8341679
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ext-object/timeout-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type TimeoutMapOptions<K, V> = TimeoutMapConstructorOptions & {
* delete handler
*/
onTimeout?: (key: K, value: V, options: TimeoutMapKeyArgs<K, V>, map: TimeoutMap<K, V>) => void;
/**
* when over limit
*/
onOverLimit?: (key: K, value: V, options: TimeoutMapKeyArgs<K, V>, map: TimeoutMap<K, V>) => void;
};

interface TimeoutMapKeyArgs<K, V> {
Expand Down Expand Up @@ -141,10 +145,7 @@ class TimeoutMap<K, V> extends Map<K, V> {
limitKeys.forEach((key) => {
const arg = this._keyArgs.get(key);
if (arg) {
console.warn(
`TimeoutMap [${key}] over limit ${this._options.maxLength}, has been deleted`,
);
arg.options?.onTimeout?.(key, super.get(key)!, this._keyArgs.get(key)!, this);
arg.options?.onOverLimit?.(key, super.get(key)!, this._keyArgs.get(key)!, this);
}
this.delete(key);
});
Expand Down

0 comments on commit 8341679

Please sign in to comment.