lib/rbbt/persist.rb in rbbt-util-5.11.5 vs lib/rbbt/persist.rb in rbbt-util-5.11.6
- old
+ new
@@ -290,16 +290,18 @@
def self.persist(name, type = nil, persist_options = {})
type ||= :marshal
return (persist_options[:repo] || Persist::MEMORY)[persist_options[:file]] ||= yield if type ==:memory and persist_options[:file] and persist_options[:persist] and persist_options[:persist] != :update
- if FalseClass != persist_options[:persist]
+ if FalseClass == persist_options[:persist]
+ yield
+ else
other_options = Misc.process_options persist_options, :other
path = persistence_path(name, persist_options, other_options || {})
case
- when type.to_sym === :memory
+ when type.to_sym == :memory
repo = persist_options[:repo] || Persist::MEMORY
repo[path] ||= yield
when (type.to_sym == :annotations and persist_options.include? :annotation_repo)
@@ -408,25 +410,39 @@
case res
when IO
res = tee_stream(res, path, type, res.respond_to?(:callback)? res.callback : nil)
ConcurrentStream.setup res do
begin
- lockfile.unlock
+ lockfile.unlock if lockfile.locked?
rescue
Log.warn "Lockfile exception: " << $!.message
end
end
+ res.abort_callback = Proc.new do
+ begin
+ lockfile.unlock if lockfile.locked?
+ rescue
+ Log.warn "Lockfile exception: " << $!.message
+ end
+ end
raise KeepLocked.new res
when TSV::Dumper
res = tee_stream(res.stream, path, type, res.respond_to?(:callback)? res.callback : nil)
ConcurrentStream.setup res do
begin
lockfile.unlock
rescue
Log.warn "Lockfile exception: " << $!.message
end
end
+ res.abort_callback = Proc.new do
+ begin
+ lockfile.unlock
+ rescue
+ Log.warn "Lockfile exception: " << $!.message
+ end
+ end
raise KeepLocked.new res
end
end
case res
@@ -438,25 +454,23 @@
when :tsv
TSV.open(res)
else
res.read
end
+ res.join if res.respond_to? :join
rescue
res.abort if res.respond_to? :abort
raise $!
- ensure
- res.join if res.respond_to? :join
end
when TSV::Dumper
begin
io = res.stream
res = TSV.open(io)
+ io.join if io.respond_to? :join
rescue
io.abort if io.respond_to? :abort
raise $!
- ensure
- io.join if io.respond_to? :join
end
end
Misc.lock(path) do
save_file(path, type, res)
@@ -470,11 +484,9 @@
FileUtils.rm path if Open.exists? path
raise $!
end
end
- else
- yield
end
end
def self.memory(name, options = {}, &block)
case options