Sha256: 512219abe2864de0038124700f3d70fdbc97b370aa3f1b1eccae59105fc6e7ff
Contents?: true
Size: 711 Bytes
Versions: 5
Compression:
Stored size: 711 Bytes
Contents
# Used to execute tasks periodically. # Execute at most once each interval (seconds). # If interval is < 0, never execute. # If interval is 0, execute every time. class Periodic # Create a periodic execution at this interval. def initialize(interval) @last_time = Clock.at(0) @interval = interval end # Runs if it has not executed in the interval,. # Skip otherwise. def check #expects a block case when @interval < 0 return when @interval == 0 yield when @interval > 0 now = Clock.now if (@last_time + @interval) < now yield @last_time = now end end end end
Version data entries
5 entries across 5 versions & 1 rubygems