Class: ThreadStorm::Execution
Overview
Encapsulates a unit of work to be sent to the thread pool.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
:nodoc:.
-
#block ⇒ Object
readonly
:nodoc:.
-
#exception ⇒ Object
If this execution finished with an exception, it is stored here.
-
#thread ⇒ Object
readonly
:nodoc:.
-
#value ⇒ Object
The value returned by the execution’s code block.
Instance Method Summary collapse
-
#duration ⇒ Object
How long this this execution ran for (i.e. finish_time - start_time) or if it hasn’t finished, how long it has been running for.
-
#finish! ⇒ Object
:nodoc:.
-
#finish_time ⇒ Object
When this execution finished running (either cleanly or with error).
-
#finished? ⇒ Boolean
True if this execution has finished running.
-
#initialize(args, default_value, &block) ⇒ Execution
constructor
:nodoc:.
-
#join ⇒ Object
Block until this execution has finished running.
-
#start! ⇒ Object
:nodoc:.
-
#start_time ⇒ Object
When this execution began to run.
-
#started? ⇒ Boolean
True if this execution has started running.
-
#timed_out! ⇒ Object
:nodoc:.
-
#timed_out? ⇒ Boolean
True if the execution went over the timeout limit.
Constructor Details
#initialize(args, default_value, &block) ⇒ Execution
:nodoc:
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/thread_storm/execution.rb', line 9 def initialize(args, default_value, &block) #:nodoc: @args = args @value = default_value @block = block @start_time = nil @finish_time = nil @exception = nil @timed_out = false @thread = nil @lock = Monitor.new @cond = @lock.new_cond end |
Instance Attribute Details
#args ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/thread_storm/execution.rb', line 7 def args @args end |
#block ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/thread_storm/execution.rb', line 7 def block @block end |
#exception ⇒ Object
If this execution finished with an exception, it is stored here.
81 82 83 |
# File 'lib/thread_storm/execution.rb', line 81 def exception @exception end |
#thread ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/thread_storm/execution.rb', line 7 def thread @thread end |
#value ⇒ Object
The value returned by the execution’s code block.
86 87 88 |
# File 'lib/thread_storm/execution.rb', line 86 def value @value end |
Instance Method Details
#duration ⇒ Object
How long this this execution ran for (i.e. finish_time - start_time) or if it hasn’t finished, how long it has been running for.
56 57 58 59 60 61 62 |
# File 'lib/thread_storm/execution.rb', line 56 def duration if finished? finish_time - start_time else Time.now - start_time end end |
#finish! ⇒ Object
:nodoc:
37 38 39 40 41 42 |
# File 'lib/thread_storm/execution.rb', line 37 def finish! #:nodoc: @lock.synchronize do @finish_time = Time.now @cond.signal end end |
#finish_time ⇒ Object
When this execution finished running (either cleanly or with error).
50 51 52 |
# File 'lib/thread_storm/execution.rb', line 50 def finish_time @finish_time end |
#finished? ⇒ Boolean
True if this execution has finished running.
45 46 47 |
# File 'lib/thread_storm/execution.rb', line 45 def finished? !!finish_time end |
#join ⇒ Object
Block until this execution has finished running.
74 75 76 77 78 |
# File 'lib/thread_storm/execution.rb', line 74 def join @lock.synchronize do @cond.wait_until{ finished? } end end |
#start! ⇒ Object
:nodoc:
22 23 24 25 |
# File 'lib/thread_storm/execution.rb', line 22 def start! #:nodoc: @thread = Thread.current @start_time = Time.now end |
#start_time ⇒ Object
When this execution began to run.
33 34 35 |
# File 'lib/thread_storm/execution.rb', line 33 def start_time @start_time end |
#started? ⇒ Boolean
True if this execution has started running.
28 29 30 |
# File 'lib/thread_storm/execution.rb', line 28 def started? !!start_time end |
#timed_out! ⇒ Object
:nodoc:
64 65 66 |
# File 'lib/thread_storm/execution.rb', line 64 def timed_out! #:nodoc: @timed_out = true end |
#timed_out? ⇒ Boolean
True if the execution went over the timeout limit.
69 70 71 |
# File 'lib/thread_storm/execution.rb', line 69 def timed_out? !!@timed_out end |