Allow giving context to database close (#520)

This commit is contained in:
Toni Spets
2023-11-14 19:28:58 +02:00
committed by GitHub
parent 977d4a5ee4
commit ae4c9918d9
3 changed files with 10 additions and 13 deletions

7
db.go
View File

@@ -317,14 +317,11 @@ func (db *DB) Open() (err error) {
}
// Close flushes outstanding WAL writes to replicas, releases the read lock,
// and closes the database.
func (db *DB) Close() (err error) {
// and closes the database. Takes a context for final sync.
func (db *DB) Close(ctx context.Context) (err error) {
db.cancel()
db.wg.Wait()
// Start a new context for shutdown since we canceled the DB context.
ctx := context.Background()
// Perform a final db sync, if initialized.
if db.db != nil {
if e := db.Sync(ctx); e != nil && err == nil {