Class: Dry::Effects::Providers::Lock::Backend
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Lock::Backend
- Extended by:
- Initializer
- Defined in:
- lib/dry/effects/providers/lock.rb
Instance Method Summary collapse
Methods included from Initializer
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, ) mutex.synchronize do if locked?(key) nil else locks[key] = Handle.new(key, ) end end end |
#locked?(key) ⇒ 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 (key) = Undefined.map(locks.fetch(key, Undefined), &:meta) Undefined.default(, 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 |