Sha256: ecc0f7e292d96f7f765665ef7cf4809a5c6c0eb8cc1ba9541d30d5655dc2030f
Contents?: true
Size: 622 Bytes
Versions: 4
Compression:
Stored size: 622 Bytes
Contents
# frozen_string_literal: true module Jaeger # Executes a given block periodically. The block will be executed only once # when interval is set to 0. class RecurringExecutor def initialize(interval:) @interval = interval end def start(&block) raise 'Already running' if @thread @thread = Thread.new do if @interval <= 0 yield else loop do yield sleep @interval end end end end def running? @thread&.alive? end def stop @thread.kill @thread = nil end end end
Version data entries
4 entries across 4 versions & 3 rubygems