Class: Concurrent::ScheduledTask
- Inherits:
-
IVar
- Object
- IVar
- Concurrent::ScheduledTask
show all
- Defined in:
- lib/concurrent/scheduled_task.rb
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.
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/concurrent/scheduled_task.rb', line 11
def initialize(intended_time, opts = {}, &block)
raise ArgumentError.new('no block given') unless block_given?
TimerSet.calculate_schedule_time(intended_time)
super(NO_VALUE, opts)
self.observers = CopyOnNotifyObserverSet.new
@intended_time = intended_time
@state = :unscheduled
@task = block
end
|
Instance Attribute Details
#schedule_time ⇒ Object
Returns the value of attribute schedule_time.
9
10
11
|
# File 'lib/concurrent/scheduled_task.rb', line 9
def schedule_time
@schedule_time
end
|
Class Method Details
.execute(intended_time, opts = {}, &block) ⇒ Object
33
34
35
|
# File 'lib/concurrent/scheduled_task.rb', line 33
def self.execute(intended_time, opts = {}, &block)
return ScheduledTask.new(intended_time, opts, &block).execute
end
|
Instance Method Details
#add_observer(*args, &block) ⇒ Object
54
55
56
57
58
|
# File 'lib/concurrent/scheduled_task.rb', line 54
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
45
46
47
48
49
50
51
|
# File 'lib/concurrent/scheduled_task.rb', line 45
def cancel
if_state(:unscheduled, :pending) do
@state = :cancelled
event.set
true
end
end
|
#cancelled? ⇒ Boolean
37
38
39
|
# File 'lib/concurrent/scheduled_task.rb', line 37
def cancelled?
state == :cancelled
end
|
#execute ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/concurrent/scheduled_task.rb', line 24
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, &method(:process_task))
self
end
end
|
#in_progress? ⇒ Boolean
41
42
43
|
# File 'lib/concurrent/scheduled_task.rb', line 41
def in_progress?
state == :in_progress
end
|