Sha256: 807f38cc7f3c14fb4ae050b681ed040218908769e4d1a32a148a046ce79a863f

Contents?: true

Size: 947 Bytes

Versions: 3

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module Coverband
  class Background
    @semaphore = Mutex.new
    @thread = nil

    def self.stop
      return unless @thread

      @semaphore.synchronize do
        if @thread
          @thread.exit
          @thread = nil
        end
      end
    end

    def self.running?
      @thread&.alive?
    end

    def self.start
      return if running?

      logger = Coverband.configuration.logger
      @semaphore.synchronize do
        return if running?

        logger.debug('Coverband: Starting background reporting')
        sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds
        @thread = Thread.new do
          loop do
            Coverband.report_coverage
            logger.debug("Coverband: Reported coverage via thread. Sleeping #{sleep_seconds}s") if Coverband.configuration.verbose
            sleep(sleep_seconds)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coverband-4.2.1.rc3 lib/coverband/integrations/background.rb
coverband-4.2.1.rc2 lib/coverband/integrations/background.rb
coverband-4.2.1.rc1 lib/coverband/integrations/background.rb