Sha256: 78767b262b74a2ee30eb7ed6c1e4db3fea81ec8d26ce72ddb00a1c7de2e7b0c2
Contents?: true
Size: 716 Bytes
Versions: 18
Compression:
Stored size: 716 Bytes
Contents
# frozen_string_literal: true # encoding: utf-8 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
18 entries across 18 versions & 1 rubygems