Class: DhanHQ::WS::CmdBus

Inherits:
Object
  • Object
show all
Defined in:
lib/DhanHQ/ws/cmd_bus.rb

Overview

Thread-safe queue that buffers subscription commands until the connection is ready to send them.

Defined Under Namespace

Classes: Command

Instance Method Summary collapse

Constructor Details

#initializeCmdBus

Returns a new instance of CmdBus.



11
12
13
# File 'lib/DhanHQ/ws/cmd_bus.rb', line 11

def initialize
  @q = Queue.new
end

Instance Method Details

#drainArray<Command>

Drains all queued commands without blocking.

Returns:



30
31
32
33
34
35
# File 'lib/DhanHQ/ws/cmd_bus.rb', line 30

def drain
  out = []
  loop { out << @q.pop(true) }
rescue ThreadError
  out
end

#sub(list) ⇒ Command

Queues a subscribe command.

Parameters:

  • list (Array<Hash>)

    Instruments to subscribe.

Returns:



19
# File 'lib/DhanHQ/ws/cmd_bus.rb', line 19

def sub(list) = @q.push(Command.new(op: :sub, payload: list))

#unsub(list) ⇒ Command

Queues an unsubscribe command.

Parameters:

  • list (Array<Hash>)

    Instruments to unsubscribe.

Returns:



25
# File 'lib/DhanHQ/ws/cmd_bus.rb', line 25

def unsub(list) = @q.push(Command.new(op: :unsub, payload: list))