class TimeScheduler
Constants
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 208 def initialize @first_counter = Hash.new{|h,k| h[k] = Counter.new } @last_counter = Hash.new{|h,k| h[k] = Counter.new } end
Public Instance Methods
active?()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 241 def active? TimeScheduler::Schedule.active? end
cancel( *topics )
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 235 def cancel( *topics ) topics.each do |topic| scheduler.cancel( topic ) end end
first_only( ident = nil, timeout: 1, &block )
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 253 def first_only( ident = nil, timeout: 1, &block ) key = [ caller[0], ident.to_s ].join(":") count = @first_counter[key].incr block.call if count == 1 ::Thread.start( key ) do |key| ::Kernel.sleep timeout @first_counter[key].decr end end
last_only( ident = nil, timeout: 1, &block )
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 263 def last_only( ident = nil, timeout: 1, &block ) key = [ caller[0], ident.to_s ].join(":") @last_counter[key].incr ::Thread.start( key ) do |key| ::Kernel.sleep timeout count = @last_counter[key].decr block.call if count == 0 end end
resume()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 249 def resume TimeScheduler::Schedule.resume end
scheduler()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 213 def scheduler @@Scheduler ||= TimeScheduler::Scheduler.new end
suspend()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 245 def suspend TimeScheduler::Schedule.suspend end
topics()
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 231 def topics scheduler.topics end
wait( topic = Time.now.iso8601(6), **option, &block )
click to toggle source
# File lib/time_scheduler/scheduler.rb, line 217 def wait( topic = Time.now.iso8601(6), **option, &block ) raise TimeScheduler::Error, "option missing." if option.empty? if scheduler.reserved?( topic ) scheduler.wait_reset( topic, **option, &block ) else if option[:action].nil? && block.nil? scheduler.wait_once( topic, **option ) else scheduler.wait_each( topic, **option, &block ) end end end