MCPcopy Index your code
hub / github.com/nodejs/node / WeakRefMap

Class WeakRefMap

lib/diagnostics_channel.js:41–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39// Can't delete when weakref count reaches 0 as it could increment again.
40// Only GC can be used as a valid time to clean up the channels map.
41class WeakRefMap extends SafeMap {
42 #finalizers = new SafeFinalizationRegistry((key) => {
43 // Check that the key doesn't have any value before deleting, as the WeakRef for the key
44 // may have been replaced since finalization callbacks aren't synchronous with GC.
45 if (!this.has(key)) this.delete(key);
46 });
47
48 set(key, value) {
49 this.#finalizers.register(value, key);
50 return super.set(key, new WeakReference(value));
51 }
52
53 get(key) {
54 return super.get(key)?.get();
55 }
56
57 has(key) {
58 return !!this.get(key);
59 }
60
61 incRef(key) {
62 return super.get(key)?.incRef();
63 }
64
65 decRef(key) {
66 return super.get(key)?.decRef();
67 }
68}
69
70function markActive(channel) {
71 // eslint-disable-next-line no-use-before-define

Callers

nothing calls this directly

Calls 2

hasMethod · 0.95
deleteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…