Method: NATS#timeout
- Defined in:
- lib/nats/client.rb
permalink #timeout(sid, timeout, opts = {}, &callback) ⇒ Object
Setup a timeout for receiving messages for the subscription.
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/nats/client.rb', line 601 def timeout(sid, timeout, opts={}, &callback) # Setup a timeout if requested return unless sub = @subs[sid] auto_unsubscribe, expected = true, 1 auto_unsubscribe = opts[:auto_unsubscribe] if opts.key?(:auto_unsubscribe) expected = opts[:expected] if opts.key?(:expected) EM.cancel_timer(sub[:timeout]) if sub[:timeout] sub[:timeout] = EM.add_timer(timeout) do unsubscribe(sid) if auto_unsubscribe callback.call(sid) if callback end sub[:expected] = expected end |