Class: Timeout::TimeoutRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysl/timeout/timeout.rb

Overview

Represents thr asking for it to be timeout at in secs seconds. At timeout, raise exc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secs, thr, exc) ⇒ TimeoutRequest

Returns a new instance of TimeoutRequest.



50
51
52
53
54
# File 'lib/rubysl/timeout/timeout.rb', line 50

def initialize(secs, thr, exc)
  @left = secs
  @thread = thr
  @exception = exc
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



56
57
58
# File 'lib/rubysl/timeout/timeout.rb', line 56

def left
  @left
end

#threadObject (readonly)

Returns the value of attribute thread.



56
57
58
# File 'lib/rubysl/timeout/timeout.rb', line 56

def thread
  @thread
end

Instance Method Details

#abortObject

Abort this request, ie, we don’t care about tracking the thread anymore.



76
77
78
79
# File 'lib/rubysl/timeout/timeout.rb', line 76

def abort
  @thread = nil
  @left = 0
end

#cancelObject

Raise @exception if @thread.



66
67
68
69
70
71
72
# File 'lib/rubysl/timeout/timeout.rb', line 66

def cancel
  if @thread and @thread.alive?
    @thread.raise @exception, "execution expired"
  end

  @left = 0
end

#elapsed(time) ⇒ Object

Called because time seconds have gone by. Returns true if the request has no more time left to run.



60
61
62
63
# File 'lib/rubysl/timeout/timeout.rb', line 60

def elapsed(time)
  @left -= time
  @left <= 0
end