module FFWD::Lifecycle
Public Instance Methods
depend_on(other_lifecycle)
click to toggle source
# File lib/ffwd/lifecycle.rb, line 71 def depend_on other_lifecycle if other_lifecycle.nil? raise "Other lifecycle must not be nil" end if (@depends ||= nil) raise "This component already depends on #{@depends}" end @depends = other_lifecycle other_lifecycle.starting do start end other_lifecycle.stopping do stop @depends = nil end end
start()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 49 def start return if started? starting_hooks.each(&:call) starting_hooks.clear @state = :started end
started?()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 63 def started? (@state ||= :none) == :started end
starting(&block)
click to toggle source
# File lib/ffwd/lifecycle.rb, line 41 def starting &block if started? block.call else starting_hooks << block end end
starting_hooks()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 26 def starting_hooks @starting_hooks ||= [] end
stop()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 56 def stop return if stopped? stopping_hooks.each(&:call) stopping_hooks.clear @state = :stopped end
stopped?()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 67 def stopped? (@state ||= :none) == :stopped end
stopping(&block)
click to toggle source
Register a callback to be executed when the Stoppable is to be stopped.
This will only be called once.
# File lib/ffwd/lifecycle.rb, line 33 def stopping &block if stopped? block.call else stopping_hooks << block end end
stopping_hooks()
click to toggle source
# File lib/ffwd/lifecycle.rb, line 22 def stopping_hooks @stopping_hooks ||= [] end