class Earl::Registry(A, M)
- Earl::Registry(A, M)
- Reference
- Object
Overview
A concurrency-safe registry of agents.
- Agents of type
A
may (un)register from the registry at any time. - Registered agents can be iterated with
#each
. - Sent messages of type
M
are broadcasted to all registered agents. - Failing to deliver a message to an agent will silently unregister it.
Concurrency
Relies on a copy-on-write array:
- (un)registering an agent will duplicate the current array (in a lock);
- iterations always iterate an immutable older reference to the array.
This assumes that agents will (un)register themselves infrequently and messages be sent much more often.
Defined in:
registry.crConstructors
Instance Method Summary
- #closed? : Bool
-
#each(&) : Nil
Iterates registered agents.
-
#register(agent : A) : Nil
Registers an agent.
-
#send(message : M) : Nil
Broadcasts a message to all registered agents at the time
-
#stop : Nil
Closes the registry, preventing agents to register, then asks all registered agents to stop.
-
#unregister(agent : A) : Nil
Unregisters an agent.
Constructor Detail
Instance Method Detail
def each(&) : Nil
#
Iterates registered agents. Always iterates agents registered at the moment the iteration is started. Newly registered agents won't be iterated, when newly unregistered agents will be.
def stop : Nil
#
Closes the registry, preventing agents to register, then asks all registered agents to stop.