Sha256: ac3631546e4c594c8a49f887d453d8c67a8e919ef73f90e58807cb51da6d1cf8

Contents?: true

Size: 402 Bytes

Versions: 3

Compression:

Stored size: 402 Bytes

Contents

# frozen_string_literal: true

class Progress
  # Repeatedly run block of code after time interval
  class Beeper
    def initialize(time)
      @thread = Thread.new do
        loop do
          @skip = false
          sleep time
          yield unless @skip
        end
      end
    end

    def restart
      @skip = true
      @thread.run
    end

    def stop
      @thread.kill
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
progress-3.6.0 lib/progress/beeper.rb
progress-3.5.2 lib/progress/beeper.rb
progress-3.5.1 lib/progress/beeper.rb