Class: Amberletters::TimeoutTrigger

Inherits:
Trigger
  • Object
show all
Defined in:
lib/amberletters.rb

Instance Attribute Summary collapse

Attributes inherited from Trigger

#exclusive, #interruption, #logger, #options, #time_to_live

Instance Method Summary collapse

Constructor Details

#initialize(expiration_time = Time.now+1.0, options = {}, &block) ⇒ TimeoutTrigger

Returns a new instance of TimeoutTrigger.



159
160
161
162
163
164
165
# File 'lib/amberletters.rb', line 159

def initialize(expiration_time=Time.now+1.0, options={}, &block)
  super(options, &block)
  @expiration_time = case expiration_time
                     when Time then expiration_time
                     when Numeric then Time.now + expiration_time
                     end
end

Instance Attribute Details

#expiration_timeObject (readonly)

Returns the value of attribute expiration_time.



157
158
159
# File 'lib/amberletters.rb', line 157

def expiration_time
  @expiration_time
end

Instance Method Details

#call(process) ⇒ Object



171
172
173
174
175
176
177
178
# File 'lib/amberletters.rb', line 171

def call(process)
  if process.time >= expiration_time
    @block.call(self, process, process.blocker)
    true
  else
    false
  end
end

#to_sObject



167
168
169
# File 'lib/amberletters.rb', line 167

def to_s
  "timeout at #{expiration_time}"
end