Files
2026-03-09 23:09:46 -04:00

87 lines
2.5 KiB
Clojure

(ns Registry
"Elixir Registry module — process registry for local name lookup.
In CljElixir: (Registry/start-link :keys :unique :name :my-registry), etc.
Registries allow processes to be found by key (unique or duplicate).")
(defn start-link
"Starts a registry. Returns {:ok pid}.
(Registry/start-link :keys :unique :name MyApp.Registry)
(Registry/start-link :keys :duplicate :name MyApp.PubSub)"
[opts])
(defn register
"Registers the current process under `key`.
(Registry/register MyApp.Registry :my-key \"value\") ;=> {:ok pid}"
[registry key value])
(defn unregister
"Unregisters the current process from `key`.
(Registry/unregister MyApp.Registry :my-key)"
[registry key])
(defn lookup
"Looks up processes registered under `key`. Returns [{pid, value} ...].
(Registry/lookup MyApp.Registry :my-key) ;=> [{#PID<0.123.0> \"value\"}]"
[registry key])
(defn dispatch
"Dispatches to all registered processes for `key`.
(Registry/dispatch MyApp.PubSub :topic (fn [{pid val}] (send pid :msg)))"
([registry key fun])
([registry key fun opts]))
(defn keys
"Returns all keys registered by the current process.
(Registry/keys MyApp.Registry (Process/self)) ;=> [:key1 :key2]"
[registry pid])
(defn values
"Returns all {pid, value} pairs for `key`.
(Registry/values MyApp.Registry :my-key (Process/self))"
[registry key pid])
(defn count
"Returns the number of registered entries.
(Registry/count MyApp.Registry) ;=> 5"
[registry])
(defn count-match
"Returns count of entries matching `key` and `pattern`.
(Registry/count-match MyApp.Registry :my-key :_)"
([registry key pattern])
([registry key pattern guards]))
(defn match
"Matches entries by key and value pattern.
(Registry/match MyApp.Registry :my-key :_) ;=> all values for key"
([registry key pattern])
([registry key pattern guards]))
(defn select
"Selects entries using match specifications."
[registry spec])
(defn update-value
"Updates the value for the current process's registration.
(Registry/update-value MyApp.Registry :my-key (fn [old] (inc old)))"
[registry key callback])
(defn unregister-match
"Unregisters entries matching key and pattern."
([registry key pattern])
([registry key pattern guards]))
(defn meta
"Gets metadata for a registry key.
(Registry/meta MyApp.Registry :my-key)"
[registry key])
(defn put-meta
"Sets metadata for a registry key."
[registry key value])
(defn child-spec
"Returns a child spec for starting under a supervisor."
[opts])