Class: Gruf::Timer::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/timer.rb

Overview

Represents a timer result that contains both the elapsed time and the result of the block

result = Timer.time { do_my_thing } result.time # => 1.10123 result.result # => 'my_thing_is_done'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, time) ⇒ Result

Initialize the result object

Parameters:

  • result (Object)

    The result of the block that was called

  • time (Float)

    The time, in ms, of the block execution



49
50
51
52
# File 'lib/gruf/timer.rb', line 49

def initialize(result, time)
  @result = result
  @time = time.to_f
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



38
39
40
# File 'lib/gruf/timer.rb', line 38

def result
  @result
end

#timeObject (readonly)

Returns the value of attribute time.



41
42
43
# File 'lib/gruf/timer.rb', line 41

def time
  @time
end

Instance Method Details

#success?Boolean

Was this result a successful result?

Returns:

  • (Boolean)

    Whether or not this result was a success



59
60
61
# File 'lib/gruf/timer.rb', line 59

def success?
  !result.is_a?(GRPC::BadStatus) && !result.is_a?(StandardError) && !result.is_a?(GRPC::Core::CallError)
end