I have a system where lots of data-objects are generated, and many are held onto by indices.
I currently calculate which are the "live" data-objects by asking each index which data-objects are needed to recreate it, and then producing a set from all the results (as multiple indices may refer to the same data-object).
(The set of "live" data-objects is required for fault tolerance, as the indices can be rebuilt from just those data-objects.)
On reading about ES6's weak references, I thought that weak reference were just what I needed:
If I had put all the data-objects into a WeakSet
, then only those that were kept "alive" by being in an index, would be present.
Then I found out that you cannot iterate the objects in a weak set.
Can ES6's WeakSet
be made to work for my use case?
If not, what are the use cases for weak references in ES6?