Closed AlttiRi closed 2 years ago
Is it really necessary to await tx.done?
tx.done
It looks that it's enough:
either
await store.add(1); await store.add(2);
or
await Promise.all([store.add(1), store.add(2)]);
In fact, it looks that I don't need even do anything above (if the both transactions are not depend each other): multiple transactions within one task execute sequentially. For example, the follow code unexpectedly works:
const store1 = db.transaction(["numbers"], "readwrite").objectStore("numbers"); store1.add(1); store1.add(2); const store2 = db.transaction(["numbers"], "readwrite").objectStore("numbers"); store2.add(3); store2.add(4); store1.add(5); store1.add(6);
There is no exception on store1.add(5);. It performs the first transaction — adds 1, 2, 5, 6, then the second transaction — adds 3, 4.
store1.add(5);
1
2
5
6
3
4
Is there an example where I need to use exactly await Promise.all([store.add(1), store.add(2), tx.done]);?
await Promise.all([store.add(1), store.add(2), tx.done]);
Is transaction may fail after all write operations are successfully completed?
I looks it's enough to use await Promise.all([store.add(1), store.add(2)]); or await tx.done; (+1-2 ms) to be sure that the transaction is completed.
await tx.done;
Yes. done is the signal that the transaction completed and everything was written to the database. https://github.com/jakearchibald/idb#txdone
done
Is it really necessary to await
tx.done
?It looks that it's enough:
either
or
In fact, it looks that I don't need even do anything above (if the both transactions are not depend each other): multiple transactions within one task execute sequentially. For example, the follow code unexpectedly works:
There is no exception on
store1.add(5);
. It performs the first transaction — adds1
,2
,5
,6
, then the second transaction — adds3
,4
.Is there an example where I need to use exactly
await Promise.all([store.add(1), store.add(2), tx.done]);
?Is transaction may fail after all write operations are successfully completed?
I looks it's enough to use
await Promise.all([store.add(1), store.add(2)]);
orawait tx.done;
(+1-2 ms) to be sure that the transaction is completed.