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.
192 193 194 195 |
# File 'lib/smith/messaging/sender.rb', line 192 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
213 214 215 |
# File 'lib/smith/messaging/sender.rb', line 213 def cancel_timeout @timeout.cancel if @timeout end |
#set_timeout(message_id) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/smith/messaging/sender.rb', line 197 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
209 210 211 |
# File 'lib/smith/messaging/sender.rb', line 209 def timeout? !@timeout_duration.nil? end |
#to_s ⇒ Object
217 218 219 |
# File 'lib/smith/messaging/sender.rb', line 217 def to_s "<Smith::Timeout: #{@timeout_duration}>" end |