Class: OKF::MCP::HTTP::Streams
- Inherits:
-
Object
- Object
- OKF::MCP::HTTP::Streams
- Defined in:
- lib/okf/mcp/http.rb
Overview
The bridge's own ledger of parked streams, one per WEBrick server. The SDK closes the streams it knows about, but a listen that races the transport's close registers after that sweep and would park forever — and a supervisor sends exactly one signal, so "the second TERM re-sweeps" is termination lost. The latch closes the race: once #close_all has run, an admitted stream is closed on the spot and its handler thread parks for no time at all.
Instance Method Summary collapse
- #admit(stream) ⇒ Object
- #close_all ⇒ Object
- #discard(stream) ⇒ Object
-
#initialize ⇒ Streams
constructor
A new instance of Streams.
Constructor Details
#initialize ⇒ Streams
Returns a new instance of Streams.
103 104 105 106 107 |
# File 'lib/okf/mcp/http.rb', line 103 def initialize @lock = Mutex.new @streams = [] @closed = false end |
Instance Method Details
#admit(stream) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/okf/mcp/http.rb', line 109 def admit(stream) late = @lock.synchronize do if @closed true else @streams << stream false end end stream.close if late end |
#close_all ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/okf/mcp/http.rb', line 125 def close_all parked = @lock.synchronize do @closed = true @streams.dup end parked.each(&:close) end |
#discard(stream) ⇒ Object
121 122 123 |
# File 'lib/okf/mcp/http.rb', line 121 def discard(stream) @lock.synchronize { @streams.delete(stream) } end |