Skip to content

Commit

Permalink
idk 2
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Nov 30, 2024
1 parent 78e0de8 commit e0a6a91
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-readers-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@verdant-web/persistence-sqlite': patch
'@verdant-web/store': patch
---

Sometimes you think you know javascript, but
11 changes: 2 additions & 9 deletions packages/persistence-sqlite/src/SqliteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ export class SqliteService extends Disposable {
constructor(protected db: Database) {
super();
const abortController = new AbortController();
this.globalAbortController = abortController;
const abort = abortController.abort.bind(abortController);
this.addDispose(function () {
if (abortController.signal.aborted) return;
try {
abort();
} catch (err) {
console.error('Error aborting global controller', err);
}
});
this.globalAbortController = abortController;
this.addDispose(abort);
}

transaction = async <T>(
Expand Down
11 changes: 2 additions & 9 deletions packages/store/src/persistence/idb/IdbService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ export class IdbService extends Disposable {
super();
this.log = log;
const abortController = new AbortController();
this.globalAbortController = abortController;
const abort = abortController.abort.bind(abortController);
this.addDispose(function () {
if (abortController.signal.aborted) return;
try {
abort();
} catch (err) {
console.error('Error aborting global controller', err);
}
});
this.globalAbortController = abortController;
this.addDispose(abort);
this.db.addEventListener('versionchange', this.onVersionChange);
this.addDispose(() => {
this.db.removeEventListener('versionchange', this.onVersionChange);
Expand Down
10 changes: 9 additions & 1 deletion packages/store/src/utils/Disposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ export class Disposable {

dispose = async () => {
this.disposed = true;
await Promise.all(this._disposes.map((dispose) => dispose()));
await Promise.all(
this._disposes.map(async (dispose) => {
try {
await dispose();
} catch (err) {
console.error('Error disposing', err);
}
}),
);
this._disposes = [];
};

Expand Down

0 comments on commit e0a6a91

Please sign in to comment.