Sha256: 2362dc65b1e17fc82af8593cf1aa9c98b8662fe68c14d1a106511aed9a4360eb
Contents?: true
Size: 549 Bytes
Versions: 3
Compression:
Stored size: 549 Bytes
Contents
# A memory lock prevents multiple requests with the same request # fingerprint from running concurrently class Idempo::MemoryLock def initialize @requests_in_flight_mutex = Mutex.new @in_progress = Set.new end def with(request_key) @requests_in_flight_mutex.synchronize do if @in_progress.include?(request_key) raise Idempo::ConcurrentRequest else @in_progress << request_key end end yield ensure @requests_in_flight_mutex.synchronize { @in_progress.delete(request_key) } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
idempo-1.3.0 | lib/idempo/memory_lock.rb |
idempo-1.2.2 | lib/idempo/memory_lock.rb |
idempo-1.2.1 | lib/idempo/memory_lock.rb |