Class: Wiris::FileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/src-generic/FileLock.rb

Constant Summary collapse

TIMEOUT =
5000
WAIT =
100

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileLock

Returns a new instance of FileLock.



11
12
13
# File 'lib/src-generic/FileLock.rb', line 11

def initialize(file)
    @file = file
end

Class Method Details

.getLock(filename, wait = 500, remaining = 0) ⇒ Object



15
16
17
18
19
20
# File 'lib/src-generic/FileLock.rb', line 15

def self.getLock(filename, wait = 500, remaining = 0)
    # Time in milliseconds
    starwait = (Time.now.to_f*1000).to_i
    file = File.new(filename + ".lock", "w+")
    return FileLock.new(file)
end

Instance Method Details

#fileObject



7
8
9
# File 'lib/src-generic/FileLock.rb', line 7

def file
    @file
end

#releaseObject



22
23
24
25
# File 'lib/src-generic/FileLock.rb', line 22

def release()
    file.close
    File.delete(file)
end