I wonder if there is a way to unregister/1
a name from one process and register/2
it to another atomically?
My use case is I want to swap processes transparently to the caller without introducing an additional process registry.
I wonder if there is a way to unregister/1
a name from one process and register/2
it to another atomically?
My use case is I want to swap processes transparently to the caller without introducing an additional process registry.
Hello!
No there is not, but you could implement it using a via
callback module for gen_server et al.
You could also use 2 different names and store the one that is βactiveβ in persistent_term
. When a process wants to send a message to it they fetch the active atom from persistent_term first.
A follow-up note regarding using via
is that if the global
module for global name registration is suitable for you, there is no need to implement your own registration module - it already has an atomic global:re_register_name/2,3
function.