Hyperlinkv0.8.0-beta.28

HashRing

HashRing.removeconsteffect/HashRing.ts:240
<A extends PrimaryKey.PrimaryKey>(node: A): (
  self: HashRing<A>
) => HashRing<A>
<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): HashRing<A>

Removes the node from the ring. No-op's if the node does not exist.

When to use

Use to remove a node that has left the pool so future lookups and shard assignments stop returning it.

Details

Removal matches by PrimaryKey.value, so any value with the same primary key removes the same ring member.

Gotchas

This mutates and returns the same ring instance.

combinatorsaddhas
Source effect/HashRing.ts:24013 lines
export const remove: {
  <A extends PrimaryKey.PrimaryKey>(node: A): (self: HashRing<A>) => HashRing<A>
  <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): HashRing<A>
} = dual(2, <A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, node: A): HashRing<A> => {
  const key = PrimaryKey.value(node)
  const entry = self.nodes.get(key)
  if (entry) {
    self.nodes.delete(key)
    self.ring = self.ring.filter(([, n]) => n !== key)
    self.totalWeightCache -= entry[1]
  }
  return self
})