Sha256: 0ff6973d4f2dd013ff94ea906f1a10b3d0a2e3cc6a1e3302ebcce94f02bf515b
Contents?: true
Size: 538 Bytes
Versions: 17
Compression:
Stored size: 538 Bytes
Contents
module Spruz module Once include File::Constants module_function def only_once(lock_filename = nil, locking_constant = nil) lock_filename ||= $0 locking_constant ||= LOCK_EX f = File.new(lock_filename, RDONLY) f.flock(locking_constant) and yield ensure if f f.flock LOCK_UN f.close end end def try_only_once(lock_filename = nil, locking_constant = nil, &block) only_once(lock_filename, locking_constant || LOCK_EX | LOCK_NB, &block) end end end
Version data entries
17 entries across 17 versions & 1 rubygems