lib/suo/client/base.rb in suo-0.3.0 vs lib/suo/client/base.rb in suo-0.3.1
- old
+ new
@@ -6,21 +6,25 @@
acquisition_delay: 0.01,
stale_lock_expiration: 3600,
resources: 1
}.freeze
+ BLANK_STR = "".freeze
+
attr_accessor :client, :key, :resources, :options
include MonitorMixin
def initialize(key, options = {})
fail "Client required" unless options[:client]
+
@options = DEFAULT_OPTIONS.merge(options)
@retry_count = (@options[:acquisition_timeout] / @options[:acquisition_delay].to_f).ceil
@client = @options[:client]
@resources = @options[:resources].to_i
@key = key
+
super() # initialize Monitor mixin for thread safety
end
def lock
token = acquire_lock
@@ -122,11 +126,11 @@
def set(newval, cas) # rubocop:disable Lint/UnusedMethodArgument
fail NotImplementedError
end
- def initial_set(val = "") # rubocop:disable Lint/UnusedMethodArgument
+ def initial_set(val = BLANK_STR) # rubocop:disable Lint/UnusedMethodArgument
fail NotImplementedError
end
def synchronize
mon_synchronize { yield }
@@ -156,10 +160,10 @@
def deserialize_and_clear_locks(val)
clear_expired_locks(deserialize_locks(val))
end
def deserialize_locks(val)
- unpacked = (val.nil? || val == "") ? [] : MessagePack.unpack(val)
+ unpacked = (val.nil? || val == BLANK_STR) ? [] : MessagePack.unpack(val)
unpacked.map do |time, token|
[Time.at(time), token]
end
rescue EOFError, MessagePack::MalformedFormatError => _