0

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?

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • ES6 doesn't have weak references. It only has weak collections, which are not [*that*](http://stackoverflow.com/q/30556078/1048572) [useful](http://stackoverflow.com/q/29413222/1048572). – Bergi Dec 09 '15 at 16:15
  • What exactly do you calculate that "live set" for? To delete the rest? – Bergi Dec 09 '15 at 16:16
  • What exactly is an "index", and how does it "hold onto the data-object(s)"? Code would help. – Bergi Dec 09 '15 at 16:16
  • The "live set" is sent to other servers, when they start, for fault tolerance, as pushing the live set through the indexes is sufficient to replicate their values. – fadedbee Dec 10 '15 at 08:33
  • An "index" is just an in-memory Javascript object which has (normal, strong) references to the data-objects which it can be queried about. – fadedbee Dec 10 '15 at 08:34
  • Thanks for the links. I now understand that ES6's weak collections are significantly less useful and less powerful than weak references. – fadedbee Dec 10 '15 at 09:05
  • @chrisdew weak references are coming - but they'll take almost another year. Of course if you're using Node there are userland weak ref implementations. – Benjamin Gruenbaum Jan 04 '16 at 09:28

0 Answers0