Class: Waithook::WebsocketClient::Waiter
- Inherits:
-
Object
- Object
- Waithook::WebsocketClient::Waiter
- Defined in:
- lib/waithook/websocket_client.rb
Overview
Waiter object, blocking current thread. Better abstraction for ruby’s Queue utility class
= Waiter.new
Thread.new { sleep 5; .notify('Done!!!') }
.wait # => return 'Done!!!' after 5 seconds pause
Instance Method Summary collapse
-
#notify(data) ⇒ Object
Notify waiting side.
-
#wait ⇒ Object
Waiting for someone to call #notify.
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 |
#wait ⇒ Object
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 |