Class: Concurrent::ScheduledTask
- Inherits:
-
IVar
- Object
- IVar
- Concurrent::ScheduledTask
show all
- Defined in:
- lib/concurrent/scheduled_task.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from IVar
#fail, #set
Methods included from Observable
#count_observers, #delete_observer, #delete_observers, #with_observer
Methods included from Obligation
#completed?, #exception, #fulfilled?, #incomplete?, #no_error!, #pending?, #reason, #rejected?, #state, #unscheduled?, #value, #value!, #wait
#value
Constructor Details
#initialize(intended_time, opts = {}, &block) ⇒ ScheduledTask
Returns a new instance of ScheduledTask.
Instance Attribute Details
#schedule_time ⇒ Object
Returns the value of attribute schedule_time.
10
11
12
|
# File 'lib/concurrent/scheduled_task.rb', line 10
def schedule_time
@schedule_time
end
|
Class Method Details
.execute(intended_time, opts = {}, &block) ⇒ Object
35
36
37
|
# File 'lib/concurrent/scheduled_task.rb', line 35
def self.execute(intended_time, opts = {}, &block)
return ScheduledTask.new(intended_time, opts, &block).execute
end
|
Instance Method Details
#add_observer(*args, &block) ⇒ Object
56
57
58
59
60
|
# File 'lib/concurrent/scheduled_task.rb', line 56
def add_observer(*args, &block)
if_state(:unscheduled, :pending, :in_progress) do
observers.add_observer(*args, &block)
end
end
|
#cancel ⇒ Object
Also known as:
stop
47
48
49
50
51
52
53
|
# File 'lib/concurrent/scheduled_task.rb', line 47
def cancel
if_state(:unscheduled, :pending) do
@state = :cancelled
event.set
true
end
end
|
#cancelled? ⇒ Boolean
39
40
41
|
# File 'lib/concurrent/scheduled_task.rb', line 39
def cancelled?
state == :cancelled
end
|
#execute ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/concurrent/scheduled_task.rb', line 26
def execute
if compare_and_set_state(:pending, :unscheduled)
@schedule_time = TimerSet.calculate_schedule_time(@intended_time)
Concurrent::timer(@schedule_time.to_f - Time.now.to_f) { @executor.post &method(:process_task) }
self
end
end
|
#in_progress? ⇒ Boolean
43
44
45
|
# File 'lib/concurrent/scheduled_task.rb', line 43
def in_progress?
state == :in_progress
end
|