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
The key.
-
#value ⇒ Object
The value.
Instance Method Summary collapse
-
#clear! ⇒ Object
Clear the instance.
-
#initialize(key, value) ⇒ Keyed
constructor
A new instance of Keyed.
-
#mark! ⇒ Object
Mark the instance.
-
#marked? ⇒ Boolean
Has the instance been marked?.
-
#stop? ⇒ Boolean
Stop the instance if it was not marked.
Constructor Details
#initialize(key, value) ⇒ Keyed
Returns a new instance of Keyed.
28 29 30 31 32 |
# File 'lib/async/container/keyed.rb', line 28 def initialize(key, value) @key = key @value = value @marked = true end |
Instance Attribute Details
#key ⇒ Object
The key. Normally a symbol or a file-system path.
36 37 38 |
# File 'lib/async/container/keyed.rb', line 36 def key @key end |
#value ⇒ Object
The value. Normally a child instance of some sort.
40 41 42 |
# File 'lib/async/container/keyed.rb', line 40 def value @value end |
Instance Method Details
#clear! ⇒ Object
Clear the instance. This is normally done before reloading a container.
54 55 56 |
# File 'lib/async/container/keyed.rb', line 54 def clear! @marked = false end |
#mark! ⇒ Object
Mark the instance. This will indiciate that the value is still in use/active.
49 50 51 |
# File 'lib/async/container/keyed.rb', line 49 def mark! @marked = true end |
#marked? ⇒ Boolean
Has the instance been marked?
44 45 46 |
# File 'lib/async/container/keyed.rb', line 44 def marked? @marked end |
#stop? ⇒ Boolean
Stop the instance if it was not marked.
59 60 61 62 63 64 |
# File 'lib/async/container/keyed.rb', line 59 def stop? unless @marked @value.stop return true end end |