Class: Solana::Ruby::Kit::RpcSubscriptions::Autopinger
- Inherits:
-
Object
- Object
- Solana::Ruby::Kit::RpcSubscriptions::Autopinger
- Extended by:
- T::Sig
- Defined in:
- lib/solana/ruby/kit/rpc_subscriptions/autopinger.rb
Overview
Sends a WebSocket ping on a fixed interval to keep the connection alive. Mirrors @solana/rpc-subscriptions autopinger.
Instance Method Summary collapse
-
#initialize(transport, interval: 5.0) ⇒ Autopinger
constructor
A new instance of Autopinger.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(transport, interval: 5.0) ⇒ Autopinger
Returns a new instance of Autopinger.
12 13 14 15 16 |
# File 'lib/solana/ruby/kit/rpc_subscriptions/autopinger.rb', line 12 def initialize(transport, interval: 5.0) @transport = transport @interval = interval @thread = T.let(nil, T.nilable(Thread)) end |
Instance Method Details
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/solana/ruby/kit/rpc_subscriptions/autopinger.rb', line 19 def start @thread = Thread.new do loop do sleep(@interval) break if @transport.publisher.closed? begin @transport.instance_variable_get(:@ws)&.send(nil, type: :ping) rescue StandardError break end end end @thread.abort_on_exception = false end |
#stop ⇒ Object
36 37 38 39 |
# File 'lib/solana/ruby/kit/rpc_subscriptions/autopinger.rb', line 36 def stop @thread&.kill @thread = nil end |