Class: Waithook::WebsocketClient::Waiter

Inherits:
Object
  • Object
show all
Defined in:
lib/waithook/websocket_client.rb

Overview

Waiter object, blocking current thread. Better abstraction for ruby’s Queue utility class

message_waiter = Waiter.new
Thread.new { sleep 5; message_waiter.notify('Done!!!') }
message_waiter.wait # => return 'Done!!!' after 5 seconds pause

Instance Method Summary collapse

Instance Method Details

#notify(data) ⇒ Object

Notify waiting side



35
36
37
# File 'lib/waithook/websocket_client.rb', line 35

def notify(data)
  @queue.push(data)
end

#waitObject

Waiting for someone to call #notify



29
30
31
32
# File 'lib/waithook/websocket_client.rb', line 29

def wait
  @queue = Queue.new
  @queue.pop(false)
end