mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
24 lines
539 B
Crystal
24 lines
539 B
Crystal
module DB
|
|
# Generic module to encapsulate disposable db resources.
|
|
module Disposable
|
|
macro included
|
|
@closed = false
|
|
end
|
|
|
|
# Closes this object.
|
|
def close
|
|
return if @closed
|
|
do_close
|
|
@closed = true
|
|
end
|
|
|
|
# Returns `true` if this object is closed. See `#close`.
|
|
def closed?
|
|
@closed
|
|
end
|
|
|
|
# Implementors overrides this method to perform resource cleanup
|
|
# If an exception is raised, the resource will not be marked as closed.
|
|
protected abstract def do_close
|
|
end
|
|
end
|