Module: SafeFlock

Defined in:
lib/safe_flock.rb,
lib/safe_flock/version.rb,
lib/safe_flock/lockfile.rb

Defined Under Namespace

Classes: Error, Locked, Lockfile

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.create(path, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/safe_flock.rb', line 9

def self.create(path, options = {})
  raise(ArgumentError, "Block required") unless block_given?
  lockfile = Lockfile.new(path, options)
  begin
    if lockfile.lock
      begin
        yield lockfile
      ensure
        lockfile.unlock
      end
    else
      raise Locked, "Timed out waiting for lock"
    end
  end
end