Class: BackgroundQueue::ServerLib::ErrorTaskList::RunAt

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/server_lib/error_task_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(at, &block) ⇒ RunAt

i dont care about thread safety: it doesnt matter if an event runs twice.



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/background_queue/server_lib/error_task_list.rb', line 92

def initialize(at, &block)
  @running = true
  @th = Thread.new {
    delay = at - Time.now.to_f 
    sleep(delay)
    if @running
      block.call
      @running = false
    end
  }
end

Instance Method Details

#cancelObject



104
105
106
107
108
# File 'lib/background_queue/server_lib/error_task_list.rb', line 104

def cancel
  return false if !@running
  @running = false
  @th.run #wake the sleep up
end

#wait_for_runObject



110
111
112
# File 'lib/background_queue/server_lib/error_task_list.rb', line 110

def wait_for_run
  @th.join
end