Class: Mutant::Parallel::Connection::Reader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/parallel/connection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Reader.

API:

  • private



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mutant/parallel/connection.rb', line 32

def initialize(*)
  super

  @buffer  = +''
  @log     = +''

  # Array of size max 1 as surrogate for
  # terrible default nil ivars.
  @errors  = []
  @lengths = []
  @results = []
end

Instance Attribute Details

#logObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



22
23
24
# File 'lib/mutant/parallel/connection.rb', line 22

def log
  @log
end

Class Method Details

.read_response(job:, **attributes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



45
46
47
48
49
50
51
52
53
54
# File 'lib/mutant/parallel/connection.rb', line 45

def self.read_response(job:, **attributes)
  reader = new(**attributes).read_till_final

  Response.new(
    error:  reader.error,
    job:,
    log:    reader.log,
    result: reader.result
  )
end

Instance Method Details

#errorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



24
25
26
# File 'lib/mutant/parallel/connection.rb', line 24

def error
  Util.max_one(@errors)
end

#read_till_finalObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength

API:

  • private



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mutant/parallel/connection.rb', line 57

def read_till_final
  readers = [response_reader, log_reader]

  until !@results.empty? || error
    status = deadline.status

    break timeout unless status.ok?

    reads, _others = io.select(readers, nil, nil, status.time_left)

    break timeout unless reads

    reads.each do |ready|
      if ready.equal?(response_reader)
        advance_result
      else
        advance_log
      end
    end
  end

  self
end

#resultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



28
29
30
# File 'lib/mutant/parallel/connection.rb', line 28

def result
  Util.max_one(@results)
end