Class: PlatformosCheck::LanguageServer::Channel
- Inherits:
-
Object
- Object
- PlatformosCheck::LanguageServer::Channel
- Defined in:
- lib/platformos_check/language_server/channel.rb
Overview
How you’d use this class:
In thread #1:
def foo
chan = Channel.create
send_request(chan.id, ...)
result = chan.pop
do_stuff_with_result(result)
ensure
chan.close
end
In thread #2:
Channel.by_id(id) << result
Constant Summary collapse
- MUTEX =
Mutex.new
- CHANNELS =
{}
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #close ⇒ Object
-
#initialize(id) ⇒ Channel
constructor
A new instance of Channel.
- #pop ⇒ Object
Constructor Details
#initialize(id) ⇒ Channel
Returns a new instance of Channel.
50 51 52 53 |
# File 'lib/platformos_check/language_server/channel.rb', line 50 def initialize(id) @id = id @response = SizedQueue.new(1) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
48 49 50 |
# File 'lib/platformos_check/language_server/channel.rb', line 48 def id @id end |
Class Method Details
.by_id(id) ⇒ Object
30 31 32 |
# File 'lib/platformos_check/language_server/channel.rb', line 30 def by_id(id) CHANNELS[id] end |
.close(id) ⇒ Object
34 35 36 |
# File 'lib/platformos_check/language_server/channel.rb', line 34 def close(id) CHANNELS.delete(id) end |
Instance Method Details
#<<(value) ⇒ Object
59 60 61 |
# File 'lib/platformos_check/language_server/channel.rb', line 59 def <<(value) @response << value end |
#close ⇒ Object
63 64 65 66 |
# File 'lib/platformos_check/language_server/channel.rb', line 63 def close @response.close Channel.close(id) end |
#pop ⇒ Object
55 56 57 |
# File 'lib/platformos_check/language_server/channel.rb', line 55 def pop @response.pop end |