You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Horde has the helpful NodeListener genserver that I've been copy-pasting into toy projects where I'm playing with DeltaCrdt. My approach to libraries built on top of DeltaCrdt has been to start the DeltaCrdt process under a supervisor, with a downstream child that bootstraps node membership. It'd be nice to have an optional NodeListener baked into DeltaCrdt - or even a setup like mine that use a supervisor.
Here's a ReplicatedMap implementation I came up with:
defmoduleReplicatedMapdouseSupervisoraliasReplicatedMap.{NodeWatcher}defstart_link(opts)doopts=Keyword.put_new(opts,:name,__MODULE__)Supervisor.start_link(__MODULE__,opts,name: :"#{opts[:name]}.Supervisor")enddefinit(opts)doname=opts[:name]members=opts[:members]||:autochildren=[{DeltaCrdt,[name: name,crdt: DeltaCrdt.AWLWWMap]},with_members(members,name)]# Restart the node watcher when the ReplicatedMap crashes# so that node membership is properly resync'd w/ the DeltaCrdt.Supervisor.init(children,strategy: :rest_for_one)end@specset_members(map::module(),members::[GenServer.server()])defset_members(map,members)whenis_list(members)doDeltaCrdt.set_neighbours(map,members)end@specput(map::module(),key::any(),value::any())::module()defput(map\\__MODULE__,key,value)doDeltaCrdt.put(map,key,value)end@specdelete(map::module(),key::any())::module()defdelete(map\\__MODULE__,key)doDeltaCrdt.delete(map,key)end@specdrop(map::module(),keys::[any()])::module()defdrop(map\\__MODULE__,keys)whenis_list(keys)doDeltaCrdt.drop(map,keys)end@specget(map::module(),key::any())::nil|any()defget(map\\__MODULE__,key)docaseDeltaCrdt.read(map,[key])do%{^key=>val}->val_->nilendenddefpwith_members(:auto,crdt_name)do{NodeWatcher,[name: :"#{crdt_name}.NodeWatcher",crdt_name: crdt_name]}enddefpwith_members(members,crdt_name)whenis_list(members)do{Task,fn->DeltaCrdt.set_neighbours(crdt_name,members)end}endend
This library has been so fun to play with, and I use it to show off "the power of Elixir/Erlang" whenever I have the chance.
The text was updated successfully, but these errors were encountered:
ckreiling
changed the title
Automatic cluster formation
Support for automatic cluster formation
Jul 24, 2021
Horde has the helpful
NodeListener
genserver that I've been copy-pasting into toy projects where I'm playing with DeltaCrdt. My approach to libraries built on top of DeltaCrdt has been to start theDeltaCrdt
process under a supervisor, with a downstream child that bootstraps node membership. It'd be nice to have an optionalNodeListener
baked intoDeltaCrdt
- or even a setup like mine that use a supervisor.Here's a ReplicatedMap implementation I came up with:
This library has been so fun to play with, and I use it to show off "the power of Elixir/Erlang" whenever I have the chance.
The text was updated successfully, but these errors were encountered: