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

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

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.

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.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mutant/parallel/connection.rb', line 27

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.



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

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.



40
41
42
43
44
45
46
47
48
49
# File 'lib/mutant/parallel/connection.rb', line 40

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.



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

def error = Util.max_one(@errors)

#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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mutant/parallel/connection.rb', line 52

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.



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

def result = Util.max_one(@results)