lib/polling.rb in polling-0.1.2 vs lib/polling.rb in polling-0.1.3
- old
+ new
@@ -28,39 +28,48 @@
yield if block_given?
end
end
interval = Validate.value interval
- unless @debug
- e.__send__(:start_print, e.stime)
- end
+ e.__send__(:start_print, e.stime)
case interval
when Array
loop { exec_arr.call interval }
else
Sleep.exec e.stime(:debug=>@debug)
loop { exec.call interval }
end
rescue => ex
- $stderr.puts ex.message
+ $stderr.puts ex.to_s
end
def async_run interval=@interval, debug=false
+ @debug ||= debug
e = Engine.new
- e.__send__(:start_print, 0)
- loop do
+
+ exec = lambda do |time|
before = Time.now
yield if block_given?
opts = {
- interval: interval,
+ interval: time,
before: before,
after: Time.now,
- debug: debug
+ debug: @debug
}
stime = e.stime_async opts
Sleep.exec stime
end
+
+ interval = Validate.value interval
+ if interval.class == Array
+ raise "Can't input Array class : #{interval}"
+ end
+
+ e.__send__(:start_print, 0)
+ loop { exec.call interval }
+ rescue => ex
+ $stderr.puts ex.to_s
end
private
def set_instance_variables variables