Sha256: 6a1058e8e0dbce752d51e1903a9c5dc6cf3db759fe26a2fb041a81d4ef5ff13f

Contents?: true

Size: 559 Bytes

Versions: 176

Compression:

Stored size: 559 Bytes

Contents

module Tins
  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

require 'tins/alias'

Version data entries

176 entries across 158 versions & 9 rubygems

Version Path
tins-1.20.0 lib/tins/once.rb
tins-1.19.0 lib/tins/once.rb
tins-1.18.0 lib/tins/once.rb
tins-1.17.0 lib/tins/once.rb
tdiary-5.0.9 vendor/bundle/gems/tins-1.16.3/lib/tins/once.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/tins-1.16.3/lib/tins/once.rb
tdiary-5.0.8 vendor/bundle/gems/tins-0.13.2/lib/tins/once.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/tins-0.13.2/lib/tins/once.rb
tdiary-5.0.7 vendor/bundle/gems/tins-1.16.3/lib/tins/once.rb
tins-1.16.3 lib/tins/once.rb
tins-1.16.2 lib/tins/once.rb
tins-1.16.1 lib/tins/once.rb
tins-1.16.0 lib/tins/once.rb
tins-1.15.1 lib/tins/once.rb
tdiary-5.0.6 vendor/bundle/gems/tins-1.15.0/lib/tins/once.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/once.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/once.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/once.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/once.rb
tins-1.15.0 lib/tins/once.rb