Module: Fargo::Supports::Timeout

Included in:
Client
Defined in:
lib/fargo/supports/timeout.rb

Instance Method Summary collapse

Instance Method Details

#timeout_response(timeout, succeed_subscription) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fargo/supports/timeout.rb', line 5

def timeout_response timeout, succeed_subscription
  thread = Thread.current

  subscribed_block = lambda do |args|
    thread.wakeup if succeed_subscription.call(*args)
  end

  id = channel.subscribe subscribed_block

  yield if block_given?
  sleep timeout

  channel.unsubscribe id
end