Class: EventMachine::Timers::Timer
- Inherits:
-
Object
- Object
- EventMachine::Timers::Timer
- Defined in:
- lib/em-timers/em-timers.rb
Class Attribute Summary collapse
-
.list ⇒ Object
readonly
Returns the value of attribute list.
Instance Attribute Summary collapse
-
#kickoff_timer ⇒ Object
readonly
Returns the value of attribute kickoff_timer.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#reschedule_timer ⇒ Object
readonly
Returns the value of attribute reschedule_timer.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(options, block) ⇒ Timer
constructor
A new instance of Timer.
- #schedule ⇒ Object
Constructor Details
Class Attribute Details
.list ⇒ Object (readonly)
Returns the value of attribute list.
8 9 10 |
# File 'lib/em-timers/em-timers.rb', line 8 def list @list end |
Instance Attribute Details
#kickoff_timer ⇒ Object (readonly)
Returns the value of attribute kickoff_timer.
14 15 16 |
# File 'lib/em-timers/em-timers.rb', line 14 def kickoff_timer @kickoff_timer end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/em-timers/em-timers.rb', line 11 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/em-timers/em-timers.rb', line 12 def @options end |
#reschedule_timer ⇒ Object (readonly)
Returns the value of attribute reschedule_timer.
13 14 15 |
# File 'lib/em-timers/em-timers.rb', line 13 def reschedule_timer @reschedule_timer end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
10 11 12 |
# File 'lib/em-timers/em-timers.rb', line 10 def tag @tag end |
Instance Method Details
#cancel ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/em-timers/em-timers.rb', line 27 def cancel if @kickoff_timer EM::cancel_timer(@kickoff_timer) @kickoff_timer = nil end if @reschedule_timer EM::cancel_timer(@reschedule_timer) @reschedule_timer = nil end Timer.list.delete(self) end |
#schedule ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/em-timers/em-timers.rb', line 38 def schedule increment = @options[:every] || 1 starting = @options[:starting] if [:cron] starting = EventMachine::Timers::CronLine.new([:cron]).next_time @kickoff_timer = EM.add_timer(calculate_delta_time(starting)) { @kickoff_timer = nil run_and_reschedule_cron } return self elsif @options[:at] || @options[:in] @repeats = false if @options[:at] starting = parse_time(@options[:at]) else starting = Time.now + parse_time(@options[:in]) end end if starting == :now run_and_reschedule(increment) return self else starting = parse_time(starting) end time = calculate_delta_time(starting) @kickoff_timer = EM.add_timer(time) { @kickoff_timer = nil run_and_reschedule(increment) } self end |