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, &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, &block) ⇒ Execution
:nodoc:
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/thread_storm/execution.rb', line 7 def initialize(args, &block) #:nodoc: @args = args @block = block @start_time = nil @finish_time = nil @value = nil @exception = nil @timed_out = false @thread = nil @mutex = Mutex.new @join = ConditionVariable.new end |
Instance Attribute Details
#args ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/thread_storm/execution.rb', line 5 def args @args end |
#block ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/thread_storm/execution.rb', line 5 def block @block end |
#exception ⇒ Object
If this execution finished with an exception, it is stored here.
79 80 81 |
# File 'lib/thread_storm/execution.rb', line 79 def exception @exception end |
#thread ⇒ Object (readonly)
:nodoc:
5 6 7 |
# File 'lib/thread_storm/execution.rb', line 5 def thread @thread end |
#value ⇒ Object
The value returned by the execution’s code block.
84 85 86 |
# File 'lib/thread_storm/execution.rb', line 84 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.
54 55 56 57 58 59 60 |
# File 'lib/thread_storm/execution.rb', line 54 def duration if finished? finish_time - start_time else Time.now - start_time end end |
#finish! ⇒ Object
:nodoc:
35 36 37 38 39 40 |
# File 'lib/thread_storm/execution.rb', line 35 def finish! #:nodoc: @mutex.synchronize do @finish_time = Time.now @join.signal end end |
#finish_time ⇒ Object
When this execution finished running (either cleanly or with error).
48 49 50 |
# File 'lib/thread_storm/execution.rb', line 48 def finish_time @finish_time end |
#finished? ⇒ Boolean
True if this execution has finished running.
43 44 45 |
# File 'lib/thread_storm/execution.rb', line 43 def finished? !!finish_time end |
#join ⇒ Object
Block until this execution has finished running.
72 73 74 75 76 |
# File 'lib/thread_storm/execution.rb', line 72 def join @mutex.synchronize do @join.wait(@mutex) unless finished? end end |
#start! ⇒ Object
:nodoc:
20 21 22 23 |
# File 'lib/thread_storm/execution.rb', line 20 def start! #:nodoc: @thread = Thread.current @start_time = Time.now end |
#start_time ⇒ Object
When this execution began to run.
31 32 33 |
# File 'lib/thread_storm/execution.rb', line 31 def start_time @start_time end |
#started? ⇒ Boolean
True if this execution has started running.
26 27 28 |
# File 'lib/thread_storm/execution.rb', line 26 def started? !!start_time end |
#timed_out! ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/thread_storm/execution.rb', line 62 def timed_out! #:nodoc: @timed_out = true end |
#timed_out? ⇒ Boolean
True if the execution went over the timeout limit.
67 68 69 |
# File 'lib/thread_storm/execution.rb', line 67 def timed_out? !!@timed_out end |