From b5ee6b7b4ee506712f51e1b90e9256c4b0c0c603 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 2 Dec 2019 17:35:47 +0100 Subject: pending operations WIP --- src/util/query.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/util/query.ts') diff --git a/src/util/query.ts b/src/util/query.ts index 5726bcaa6..6942d471e 100644 --- a/src/util/query.ts +++ b/src/util/query.ts @@ -351,15 +351,32 @@ class TransactionHandle { } } +export function runWithReadTransaction( + db: IDBDatabase, + stores: Store[], + f: (t: TransactionHandle) => Promise, +): Promise { + return runWithTransaction(db, stores, f, "readonly"); +} + export function runWithWriteTransaction( db: IDBDatabase, stores: Store[], f: (t: TransactionHandle) => Promise, +): Promise { + return runWithTransaction(db, stores, f, "readwrite"); +} + +function runWithTransaction( + db: IDBDatabase, + stores: Store[], + f: (t: TransactionHandle) => Promise, + mode: "readonly" | "readwrite", ): Promise { const stack = Error("Failed transaction was started here."); return new Promise((resolve, reject) => { const storeName = stores.map(x => x.name); - const tx = db.transaction(storeName, "readwrite"); + const tx = db.transaction(storeName, mode); let funResult: any = undefined; let gotFunResult: boolean = false; tx.oncomplete = () => { -- cgit v1.2.3