Class: ThemeCheck::LanguageServer::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Channel

Returns a new instance of Channel.



50
51
52
53
# File 'lib/theme_check/language_server/channel.rb', line 50

def initialize(id)
  @id = id
  @response = SizedQueue.new(1)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



48
49
50
# File 'lib/theme_check/language_server/channel.rb', line 48

def id
  @id
end

Class Method Details

.by_id(id) ⇒ Object



30
31
32
# File 'lib/theme_check/language_server/channel.rb', line 30

def by_id(id)
  CHANNELS[id]
end

.close(id) ⇒ Object



34
35
36
# File 'lib/theme_check/language_server/channel.rb', line 34

def close(id)
  CHANNELS.delete(id)
end

.createObject



24
25
26
27
28
# File 'lib/theme_check/language_server/channel.rb', line 24

def create
  id = new_id
  CHANNELS[id] = new(id)
  CHANNELS[id]
end

Instance Method Details

#<<(value) ⇒ Object



59
60
61
# File 'lib/theme_check/language_server/channel.rb', line 59

def <<(value)
  @response << value
end

#closeObject



63
64
65
66
# File 'lib/theme_check/language_server/channel.rb', line 63

def close
  @response.close
  Channel.close(id)
end

#popObject



55
56
57
# File 'lib/theme_check/language_server/channel.rb', line 55

def pop
  @response.pop
end