Sha256: 33bc89049052e614e4939bdc88ff49dece459d57ace8575c697c12253eafabeb
Contents?: true
Size: 536 Bytes
Versions: 4
Compression:
Stored size: 536 Bytes
Contents
require 'morlock/gem_client' class Morlock DEFAULT_EXPIRATION = 60 attr_accessor :client def initialize(client) @client = Morlock::GemClient.wrap(client) end def lock(key, options = {}) lock_obtained = @client.add(key, options[:expiration] || DEFAULT_EXPIRATION) yield if lock_obtained && block_given? options[:success].call if lock_obtained && options[:success] options[:failure].call if !lock_obtained && options[:failure] lock_obtained ensure @client.delete(key) if lock_obtained end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
morlock-0.0.4 | lib/morlock/base.rb |
morlock-0.0.3 | lib/morlock/base.rb |
morlock-0.0.2 | lib/morlock/base.rb |
morlock-0.0.1 | lib/morlock/base.rb |