Class: Daemon::Utils::ProcessCache
- Inherits:
-
Object
- Object
- Daemon::Utils::ProcessCache
- Defined in:
- lib/onapp/engine/utils/process_cache.rb
Instance Method Summary (collapse)
- - (Object) access
-
- (ProcessCache) initialize(accessor, destructor = proc{})
constructor
A new instance of ProcessCache.
Constructor Details
- (ProcessCache) initialize(accessor, destructor = proc{})
Returns a new instance of ProcessCache
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/onapp/engine/utils/process_cache.rb', line 6 def initialize(accessor, destructor = proc{}) unless accessor.respond_to?(:call) && destructor.respond_to?(:call) raise ArgumentError, 'Require block here' end @accessor = accessor @destructor = destructor @pid = nil extend(::MonitorMixin) end |
Instance Method Details
- (Object) access
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/onapp/engine/utils/process_cache.rb', line 17 def access synchronize do if @pid && @pid != ::Process.pid @destructor.call end if @pid == ::Process.pid @cache else @pid = ::Process.pid @cache = @accessor.call end end end |