Class: Async::Container::Keyed

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Keyed

Returns a new instance of Keyed.



11
12
13
14
15
# File 'lib/async/container/keyed.rb', line 11

def initialize(key, value)
	@key = key
	@value = value
	@marked = true
end

Instance Attribute Details

#keyObject

The key. Normally a symbol or a file-system path.



19
20
21
# File 'lib/async/container/keyed.rb', line 19

def key
  @key
end

#valueObject

The value. Normally a child instance of some sort.



23
24
25
# File 'lib/async/container/keyed.rb', line 23

def value
  @value
end

Instance Method Details

#clear!Object

Clear the instance. This is normally done before reloading a container.



37
38
39
# File 'lib/async/container/keyed.rb', line 37

def clear!
	@marked = false
end

#mark!Object

Mark the instance. This will indiciate that the value is still in use/active.



32
33
34
# File 'lib/async/container/keyed.rb', line 32

def mark!
	@marked = true
end

#marked?Boolean

Has the instance been marked?

Returns:

  • (Boolean)


27
28
29
# File 'lib/async/container/keyed.rb', line 27

def marked?
	@marked
end

#stop?Boolean

Stop the instance if it was not marked.

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/async/container/keyed.rb', line 42

def stop?
	unless @marked
		@value.stop
		return true
	end
end