Skip to content

Commit

Permalink
fix: resolve potential errors during garbage collection process
Browse files Browse the repository at this point in the history
  • Loading branch information
izure1 committed Nov 20, 2024
1 parent 2d2fa74 commit ec6e8ed
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@izure/cache-entanglement",
"version": "1.2.1",
"version": "1.2.2",
"description": "Manage caches that are dependent on each other efficiently.",
"author": "izure1 <admin@izure.org>",
"license": "MIT",
Expand Down
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cache-entanglement",
"version": "1.2.1",
"version": "1.2.2",
"description": "Manage caches that are dependent on each other efficiently.",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down Expand Up @@ -32,7 +32,6 @@
"license": "MIT",
"devDependencies": {
"@types/jest": "^29.5.13",
"@types/ungap__structured-clone": "^1.2.0",
"esbuild": "^0.24.0",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
Expand Down
2 changes: 1 addition & 1 deletion src/CacheEntanglement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CacheData } from './CacheData'
import { InvertedWeakMap } from './utils/InvertWeakMap'
import { InvertedWeakMap } from './utils/InvertedWeakMap'

type Deferred<T> = T|Promise<T>
type ValueRecord<T> = { [key: string]: T }
Expand Down
7 changes: 7 additions & 0 deletions src/utils/InvertWeakMap.ts → src/utils/InvertedWeakMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export class InvertedWeakMap<K extends string|number|symbol, V extends WeakKey>
}

delete(key: K): boolean {
const ref = this._map.get(key)
if (ref) {
const raw = ref.deref()
if (raw !== undefined) {
this._registry.unregister(raw)
}
}
return this._map.delete(key)
}

Expand Down

0 comments on commit ec6e8ed

Please sign in to comment.