594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
# File 'ext/lib/tk/timer.rb', line 594
def set_next_callback(args)
if @running == false || @proc_max == 0 || @do_loop == 0
Tk_CBTBL.delete(@id) ;
@running = false
__at_end__
return
end
if @current_pos >= @proc_max
if @do_loop < 0 || (@do_loop -= 1) > 0
@current_pos = 0
else
Tk_CBTBL.delete(@id) ;
@running = false
__at_end__
return
end
end
@current_args = args
cmd, *cmd_args = @loop_proc[@current_pos]
@current_pos += 1
@current_proc = cmd
@offset_s, @offset_u = _offset_ave
if TkComm._callback_entry?(@sleep_time)
sleep = @sleep_time.call(self)
else
sleep = @sleep_time
end
if @est_time
@est_time = Time.at(@est_time.to_i, @est_time.usec + sleep*1000)
else
@est_time = Time.at(@cb_start_time.to_i,
@cb_start_time.usec + sleep*1000)
end
now = Time.now
real_sleep = ((@est_time.to_i - now.to_i + @offset_s)*1000.0 +
(@est_time.usec - now.usec + @offset_u)/1000.0).round
if real_sleep <= 0
real_sleep = 0
@offset_s = now.to_i
@offset_u = now.usec
end
@current_sleep = real_sleep
set_callback(real_sleep, cmd_args)
end
|