Class: WhiteGold::Job
Constant Summary collapse
- NO_RESULT =
Object.new
Instance Method Summary collapse
- #audit ⇒ Object
- #finish(result = NO_RESULT) ⇒ Object
-
#initialize(delay:, repeat:, run: true, &b) ⇒ Job
constructor
A new instance of Job.
- #on_done(&b) ⇒ Object
- #run ⇒ Object
Constructor Details
Instance Method Details
#audit ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/white_gold/master.rb', line 119 def audit if @thread if @thread.alive? return true else @on_done.(@result) if @on_done if @repeat run return true else return false end end else return true end end |
#finish(result = NO_RESULT) ⇒ Object
137 138 139 140 |
# File 'lib/white_gold/master.rb', line 137 def finish result = NO_RESULT @repeat = false @result = result if result != NO_RESULT end |
#on_done(&b) ⇒ Object
114 115 116 117 |
# File 'lib/white_gold/master.rb', line 114 def on_done &b @on_done = b b.(@result) if @thread && !@thread.alive? end |
#run ⇒ Object
107 108 109 110 111 112 |
# File 'lib/white_gold/master.rb', line 107 def run @thread = Thread.new do sleep(@delay / 1000.0) if @delay @result = @job.(self) end end |