Sha256: be5e2af1913cb1d704d68bb862f579b019096d38fd347b85fd082d3e7b4896de

Contents?: true

Size: 509 Bytes

Versions: 2

Compression:

Stored size: 509 Bytes

Contents

# frozen_string_literal: true

require 'timeout'

module ACE
  class FileMutex
    def initialize(lock_file)
      @lock_file = lock_file
    end

    def with_read_lock
      fh = File.open(@lock_file, File::CREAT)
      fh.flock(File::LOCK_SH)
      yield
    ensure
      fh.flock(File::LOCK_UN)
      fh.close
    end

    def with_write_lock
      fh = File.open(@lock_file, File::CREAT)
      fh.flock(File::LOCK_EX)
      yield
    ensure
      fh.flock(File::LOCK_UN)
      fh.close
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
agentless-catalog-executor-1.1.0 lib/ace/file_mutex.rb
agentless-catalog-executor-1.0.0 lib/ace/file_mutex.rb