Class: Smith::Messaging::Timeout
- Inherits:
-
Object
- Object
- Smith::Messaging::Timeout
- Defined in:
- lib/smith/messaging/sender.rb
Instance Method Summary collapse
- #cancel_timeout ⇒ Object
-
#initialize(timeout, opts = {}, &blk) ⇒ Timeout
constructor
A new instance of Timeout.
- #set_timeout(message_id) ⇒ Object
- #timeout? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(timeout, opts = {}, &blk) ⇒ Timeout
Returns a new instance of Timeout.
209 210 211 212 |
# File 'lib/smith/messaging/sender.rb', line 209 def initialize(timeout, opts={}, &blk) @timeout_proc = blk || proc { || raise MessageTimeoutError, "Message not received within the timeout period#{() ? ": #{}" : ""}" } @timeout_duration = timeout end |
Instance Method Details
#cancel_timeout ⇒ Object
230 231 232 |
# File 'lib/smith/messaging/sender.rb', line 230 def cancel_timeout @timeout.cancel if @timeout end |
#set_timeout(message_id) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/smith/messaging/sender.rb', line 214 def set_timeout() @message_id = cancel_timeout if @timeout_duration @timeout = EventMachine::Timer.new(@timeout_duration) do @timeout_proc.call(, @timeout_duration) end else raise ArgumentError, "on_timeout not set." end end |
#timeout? ⇒ Boolean
226 227 228 |
# File 'lib/smith/messaging/sender.rb', line 226 def timeout? !@timeout_duration.nil? end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/smith/messaging/sender.rb', line 234 def to_s "<Smith::Timeout: #{@timeout_duration}>" end |