Class: DhanHQ::WS::CmdBus
- Inherits:
-
Object
- Object
- DhanHQ::WS::CmdBus
- 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
-
#drain ⇒ Array<Command>
Drains all queued commands without blocking.
-
#initialize ⇒ CmdBus
constructor
A new instance of CmdBus.
-
#sub(list) ⇒ Command
Queues a subscribe command.
-
#unsub(list) ⇒ Command
Queues an unsubscribe command.
Constructor Details
#initialize ⇒ CmdBus
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
#drain ⇒ Array<Command>
Drains all queued commands without blocking.
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 |