![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/lib/gems/2.5.0/gems/eventmachine-1.2.7/lib/em/ |
Upload File : |
module EventMachine # Creates a one-time timer # # timer = EventMachine::Timer.new(5) do # # this will never fire because we cancel it # end # timer.cancel # class Timer # Create a new timer that fires after a given number of seconds def initialize interval, callback=nil, &block @signature = EventMachine::add_timer(interval, callback || block) end # Cancel the timer def cancel EventMachine.send :cancel_timer, @signature end end # Creates a periodic timer # # @example # n = 0 # timer = EventMachine::PeriodicTimer.new(5) do # puts "the time is #{Time.now}" # timer.cancel if (n+=1) > 5 # end # class PeriodicTimer # Create a new periodic timer that executes every interval seconds def initialize interval, callback=nil, &block @interval = interval @code = callback || block @cancelled = false @work = method(:fire) schedule end # Cancel the periodic timer def cancel @cancelled = true end # Fire the timer every interval seconds attr_accessor :interval # @private def schedule EventMachine::add_timer @interval, @work end # @private def fire unless @cancelled @code.call schedule end end end end