mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
ensure db is closed after block
avoid GC Warning
This commit is contained in:
parent
ee21fcfea6
commit
2cb37d374c
2 changed files with 7 additions and 2 deletions
|
@ -22,6 +22,8 @@ module DB
|
|||
# Closes all connection to the database.
|
||||
def close
|
||||
@connection.try &.close
|
||||
# prevent GC Warning: Finalization cycle involving discovered by mysql implementation
|
||||
@connection = nil
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
|
|
|
@ -101,8 +101,11 @@ module DB
|
|||
# Same as `#open` but the database is yielded and closed automatically.
|
||||
def self.open(uri : URI | String, &block)
|
||||
build_database(uri).tap do |db|
|
||||
yield db
|
||||
db.close
|
||||
begin
|
||||
yield db
|
||||
ensure
|
||||
db.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue