Class: Async::Container::Keyed
- Inherits:
-
Object
- Object
- Async::Container::Keyed
- Defined in:
- lib/async/container/keyed.rb
Overview
Tracks a key/value pair such that unmarked keys can be identified and cleaned up. This helps implement persistent processes that start up child processes per directory or configuration file. If those directories and/or configuration files are removed, the child process can then be cleaned up automatically, because those key/value pairs will not be marked when reloading the container.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#clear! ⇒ Object
Clear the instance.
-
#initialize(key, value) ⇒ Keyed
constructor
Initialize the keyed instance.
-
#mark! ⇒ Object
Mark the instance.
- #marked? ⇒ Boolean
-
#stop? ⇒ Boolean
Stop the instance if it was not marked.
- #The key value, normally a symbol or a file-system path.=(keyvalue, normallyasymbol) ⇒ Object
- #The value, normally a child instance.=(value, normallyachildinstance. = (value)) ⇒ Object
Constructor Details
#initialize(key, value) ⇒ Keyed
Initialize the keyed instance
15 16 17 18 19 |
# File 'lib/async/container/keyed.rb', line 15 def initialize(key, value) @key = key @value = value @marked = true end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
22 23 24 |
# File 'lib/async/container/keyed.rb', line 22 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
25 26 27 |
# File 'lib/async/container/keyed.rb', line 25 def value @value end |
Instance Method Details
#clear! ⇒ Object
Clear the instance. This is normally done before reloading a container.
38 39 40 |
# File 'lib/async/container/keyed.rb', line 38 def clear! @marked = false end |
#mark! ⇒ Object
Mark the instance. This will indiciate that the value is still in use/active.
33 34 35 |
# File 'lib/async/container/keyed.rb', line 33 def mark! @marked = true end |
#marked? ⇒ Boolean
28 29 30 |
# File 'lib/async/container/keyed.rb', line 28 def marked? @marked end |
#stop? ⇒ Boolean
Stop the instance if it was not marked.
45 46 47 48 49 50 |
# File 'lib/async/container/keyed.rb', line 45 def stop? unless @marked @value.stop return true end end |
#The key value, normally a symbol or a file-system path.=(keyvalue, normallyasymbol) ⇒ Object
22 |
# File 'lib/async/container/keyed.rb', line 22 attr :key |
#The value, normally a child instance.=(value, normallyachildinstance. = (value)) ⇒ Object
25 |
# File 'lib/async/container/keyed.rb', line 25 attr :value |