Class: CLI::UI::StdoutRouter::Capture::BlockingInput

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/cli/ui/stdout_router.rb

Constant Summary collapse

READING_METHODS =
[
  :each,
  :each_byte,
  :each_char,
  :each_codepoint,
  :each_line,
  :getbyte,
  :getc,
  :getch,
  :gets,
  :read,
  :read_nonblock,
  :readbyte,
  :readchar,
  :readline,
  :readlines,
  :readpartial,
]
NON_READING_METHODS =
IO.instance_methods(false) - READING_METHODS

Instance Method Summary collapse

Methods included from T::Sig

sig

Constructor Details

#initialize(stream) ⇒ BlockingInput

Returns a new instance of BlockingInput.



265
266
267
268
# File 'lib/cli/ui/stdout_router.rb', line 265

def initialize(stream)
  @stream = stream
  @m = CLI::UI::ReentrantMutex.new
end

Instance Method Details

#synchronize(&block) ⇒ Object



271
272
273
274
275
276
277
278
279
# File 'lib/cli/ui/stdout_router.rb', line 271

def synchronize(&block)
  @m.synchronize do
    previous_allowed_to_read = Thread.current[:cliui_allowed_to_read]
    Thread.current[:cliui_allowed_to_read] = true
    block.call
  ensure
    Thread.current[:cliui_allowed_to_read] = previous_allowed_to_read
  end
end