dominictarr / crdt

Commutative Replicated Data Types for easy collaborative/distributed systems.
MIT License
836 stars 43 forks source link

remove inside forEach #22

Closed juliangruber closed 11 years ago

juliangruber commented 11 years ago

What this gist does is it puts 10 rows into a Set and then tries to delete all of them.

Only half get deleted.

What fixes it is slicing the _array before iterating over it.

Set.prototype.forEach = function (iter) {
  return this._array.slice().forEach(iter)
}

Or should I do this myself by calling Task.asArray().slice().forEach()?

dominictarr commented 11 years ago

hmm, what happens if you try to delete items inside forEach on a normal array?

dominictarr commented 11 years ago

Normally, I iterate backwards when I delete items in an array, then removing an item doesn't change the indexes of the items that I havn't looked at yet.

juliangruber commented 11 years ago

bad things :D I just have to get my mind into this-is-just-in-memory-and-synchronous space.