Class: Dry::Effects::Providers::Lock::Backend

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Defined in:
lib/dry/effects/providers/lock.rb

Instance Method Summary collapse

Methods included from Initializer

extended

Instance Method Details

#lock(key, meta) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/dry/effects/providers/lock.rb', line 24

def lock(key, meta)
  mutex.synchronize do
    if locked?(key)
      nil
    else
      locks[key] = Handle.new(key, meta)
    end
  end
end

#locked?(key) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dry/effects/providers/lock.rb', line 34

def locked?(key)
  locks.key?(key)
end

#meta(key) ⇒ Object



49
50
51
52
# File 'lib/dry/effects/providers/lock.rb', line 49

def meta(key)
  meta = Undefined.map(locks.fetch(key, Undefined), &:meta)
  Undefined.default(meta, nil)
end

#unlock(handle) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/dry/effects/providers/lock.rb', line 38

def unlock(handle)
  mutex.synchronize do
    if locked?(handle.key)
      locks.delete(handle.key)
      true
    else
      false
    end
  end
end