Sha256: f5c6bc26b0b9376f32256fd5ff8d8c70cf1272395aafc8b6a78aadadb74133da
Contents?: true
Size: 678 Bytes
Versions: 5
Compression:
Stored size: 678 Bytes
Contents
require 'transaction_event_store_mongoid/lock' module TransactionEventStoreMongoid class Locker attr_reader :adapter, :timeout, :retry_interval def initialize(timeout: 10, retry_interval: 0.1, adapter: ::TransactionEventStoreMongoid::Lock.new) @timeout = timeout @retry_interval = retry_interval @adapter = adapter end def with_lock(stream, &block) begin start = Time.now adapter.with_lock(stream, &block) rescue TransactionEventStore::CannotObtainLock if (Time.now - start) < timeout sleep(retry_interval) retry else raise end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems