Fix bug in Database.Transaction() of not awaiting this.mutex.acquire()
authorNick Downing <nick@ndcode.org>
Thu, 13 Jan 2022 04:00:46 +0000 (15:00 +1100)
committerNick Downing <nick@ndcode.org>
Thu, 13 Jan 2022 04:01:33 +0000 (15:01 +1100)
Database.mjs
json_to_logjson.mjs
logjson_to_json.mjs
tests/a.mjs
tests/b.mjs

index f0d40a4..01db430 100644 (file)
@@ -241,8 +241,8 @@ class Database {
     this.write_list_len = 0
   }
 
-  Transaction() {
-    this.mutex.acquire()
+  async Transaction() {
+    await this.mutex.acquire()
     return new Transaction(this, this.value)
   }
 
index 8112857..3a19bff 100755 (executable)
@@ -10,7 +10,7 @@ if (process.argv.length < 4) {
 
 let database = new logjson.Database()
 await database.open(process.argv[3])
-let transaction = database.Transaction()
+let transaction = await database.Transaction()
 transaction.set(
   transaction.json_to_logjson(
     JSON.parse(
index 77511cd..25de50f 100755 (executable)
@@ -10,7 +10,7 @@ if (process.argv.length < 4) {
 
 let database = new logjson.Database()
 await database.open(process.argv[2])
-let transaction = database.Transaction()
+let transaction = await database.Transaction()
 await fsPromises.writeFile(
   process.argv[3],
   Buffer.from(
index ccaacfb..e72aadf 100755 (executable)
@@ -6,7 +6,7 @@ import fsPromises from 'fs/promises'
 let database = new logjson.Database(5, 1)
 await database.open('a.logjson')
 
-let transaction = database.Transaction()
+let transaction = await database.Transaction()
 transaction.set(
   transaction.json_to_logjson(
     JSON.parse(await fsPromises.readFile('random.json', 'utf-8'))
@@ -14,7 +14,7 @@ transaction.set(
 )
 await transaction.commit()
 
-/*let*/ transaction = database.Transaction()
+/*let*/ transaction = await database.Transaction()
 await fsPromises.writeFile(
   'a.json',
   Buffer.from(
@@ -34,7 +34,7 @@ await database.kick()
 await database.kick()
 await database.kick()
 
-/*let*/ transaction = database.Transaction()
+/*let*/ transaction = await database.Transaction()
 await fsPromises.writeFile(
   'b.json',
   Buffer.from(
index fba6893..2ec757b 100755 (executable)
@@ -5,7 +5,7 @@ import fsPromises from 'fs/promises'
 
 let database = new logjson.Database()
 await database.open('a.logjson')
-let transaction = database.Transaction()
+let transaction = await database.Transaction()
 await fsPromises.writeFile(
   'd.json',
   Buffer.from(