@@ -42,8 +42,18 @@ def <=>(other)
4242 self . schedule_time <=> other . schedule_time
4343 end
4444
45+ # Has the task been cancelled?
46+ #
47+ # @return [Boolean] true if the task is in the given state else false
4548 def cancelled?
46- state == :cancelled
49+ synchronize { ns_check_state? ( :cancelled ) }
50+ end
51+
52+ # In the task execution in progress?
53+ #
54+ # @return [Boolean] true if the task is in the given state else false
55+ def processing?
56+ synchronize { ns_check_state? ( :processing ) }
4757 end
4858
4959 def cancel
@@ -57,17 +67,12 @@ def cancel
5767 end
5868 end
5969
60- # def reset
61- # reschedule( synchronize{ @delay })
62- # end
70+ def reset
71+ synchronize { ns_reschedule ( @delay ) }
72+ end
6373
6474 def reschedule ( delay )
65- synchronize do
66- return false unless ns_check_state? ( :pending )
67- ns_set_delay_and_time! ( delay )
68- return false unless @parent . send ( :remove_task , self )
69- @parent . send ( :ns_post_task , self )
70- end
75+ synchronize { ns_reschedule ( delay ) }
7176 end
7277
7378 # @!visibility private
@@ -83,6 +88,13 @@ def ns_set_delay_and_time!(delay)
8388 @delay = TimerSet . calculate_delay! ( delay )
8489 @time = Concurrent . monotonic_time + @delay
8590 end
91+
92+ def ns_reschedule ( delay )
93+ return false unless ns_check_state? ( :pending )
94+ ns_set_delay_and_time! ( delay )
95+ return false unless @parent . send ( :remove_task , self )
96+ @parent . send ( :ns_post_task , self )
97+ end
8698 end
8799
88100 # Create a new set of timed tasks.
0 commit comments