Module: BitShares::WSocket
- Defined in:
- lib/bitshares/wsocket.rb
Class Method Summary collapse
- .get_notice ⇒ Object
- .lock ⇒ Object
- .send(hash) ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
- .thread ⇒ Object
Class Method Details
.get_notice ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/bitshares/wsocket.rb', line 56 def get_notice if @msgs.key?('notice') && !@msgs['notice'].nil? msg = @msgs['notice'] lock.synchronize do @msgs['notice'] = nil end msg else nil end end |
.lock ⇒ Object
54 |
# File 'lib/bitshares/wsocket.rb', line 54 def lock() @lock ||= Mutex.new end |
.send(hash) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bitshares/wsocket.rb', line 31 def send hash id = hash[:id] count = 0 while @msgs[id] != nil do sleep 0.1 count += 1 raise "TimeoutError..." if count > 100 end @thread[:ws].send hash.to_json if @status == :connected count = 0 while @msgs[id].nil? and @status == :connected do sleep 0.1 count += 1 raise "TimeoutError..." if count > 100 end result = @msgs[id] lock.synchronize do @msgs[id] = nil end result end |
.start ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bitshares/wsocket.rb', line 8 def start @msgs = {} @thread ||= Thread.new { run } Thread.new do while @status != :disconnected do @thread[:ws].ping 'Hi' if @status == :connected sleep 50 end end count = 0 while @status != :connected and @status != :disconnected do sleep 0.1 count += 1 raise "TimeoutError..." if count > 100 end end |
.stop ⇒ Object
27 28 29 |
# File 'lib/bitshares/wsocket.rb', line 27 def stop EventMachine.stop end |
.thread ⇒ Object
25 |
# File 'lib/bitshares/wsocket.rb', line 25 def thread() @thread end |