Sha256: 796b2ad0b01302ca7fcbee6a97d470fc14d1b84b4e643f80a236f7a172eb1a57
Contents?: true
Size: 667 Bytes
Versions: 23
Compression:
Stored size: 667 Bytes
Contents
require 'singleton' class LocalResourceRegistry include Singleton def initialize @resources = [] end def register(resource, finalizer) @resources << [resource, finalizer] # Return resource for chaining resource end def unregister(resource) @resources.delete_if do |_resource, finalizer| _resource == resource end end def close_all @resources.each do |resource, finalizer| if finalizer.is_a?(Symbol) resource.send(finalizer) elsif finalizer.is_a?(Proc) finalizer.call(resource) else raise "Unknown finalizer: #{finalizer}" end end @resources = [] end end
Version data entries
23 entries across 23 versions & 1 rubygems