class Arachni::Reactor::Tasks::Periodic
@note {#interval Time} accuracy cannot be guaranteed.
{Base Task} occurring every {#interval} seconds.
@author Tasos “Zapotek” Laskos <tasos.laskos@gmail.com>
Attributes
interval[R]
@return [Float]
Public Class Methods
new( interval, &task )
click to toggle source
@param [Float] interval
Needs to be greater than `0.0`.
@param [#call] task
Calls superclass method
# File lib/arachni/reactor/tasks/periodic.rb, line 26 def initialize( interval, &task ) interval = interval.to_f fail ArgumentError, 'Interval needs to be greater than 0.' if interval <= 0 super( &task ) @interval = interval calculate_next end
Public Instance Methods
call( *args )
click to toggle source
@return [Object, nil]
Return value of the configured task or `nil` if it's not {#interval time} yet.
Calls superclass method
# File lib/arachni/reactor/tasks/periodic.rb, line 39 def call( *args ) return if !call? calculate_next super( *args ) end
Private Instance Methods
calculate_next()
click to toggle source
# File lib/arachni/reactor/tasks/periodic.rb, line 52 def calculate_next @next = Time.now + @interval end
call?()
click to toggle source
# File lib/arachni/reactor/tasks/periodic.rb, line 48 def call? Time.now >= @next end