idb icon indicating copy to clipboard operation
idb copied to clipboard

DeleteDB should call Close()

Open wparad opened this issue 10 months ago • 5 comments

DeleteDB always gets blocked because the database is never closed. It should automatically be closed on Delete.

Otherwise something like this is necessary:

unwrap(await db).close();
await new Promise(resolve => setTimeout(resolve, 10000));

const deleteAsync = deleteDB(databaseName, {
    blocked(blockedVersion, blockedEvent) {
          logger.error({ title: 'Database blocked from being deleted', blockedVersion, blockedEvent });
    }
}

wparad avatar Apr 11 '24 20:04 wparad

Why not just db.close()?

retorquere avatar Sep 04 '24 13:09 retorquere

and why the wait? db is not intrinsically a promise, right? If you do const db = await openDB(...), db is a IDBP, not a Promise for an IDBP.

retorquere avatar Sep 04 '24 13:09 retorquere

This works for me:

const db = openDB(.., {
  blocked: () => db.close()
})

...

deleteDB(db)

retorquere avatar Sep 04 '24 17:09 retorquere

I don't believe the types supported that. But I can always check again.

And close is async, and I believe blocked doesn't handle promises well. But something might have changed.

wparad avatar Sep 04 '24 18:09 wparad

So how should I ascertain I can delete the database?

Is close async? Close on plain indexeddb doesn't have event handlers right? If so, why would it be async in this library?

retorquere avatar Sep 04 '24 19:09 retorquere