From f6a4e93a233343dcf5b6dd7f780f48d962ad435d Mon Sep 17 00:00:00 2001 From: Roman Storm Date: Tue, 16 Feb 2021 22:08:12 -0800 Subject: [PATCH] fix mutex --- src/Transaction.js | 4 ++-- test/TxManager.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Transaction.js b/src/Transaction.js index a4d5ba2..5323841 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -96,7 +96,7 @@ class Transaction { * @private */ async _execute() { - await this.manager._mutex.acquire() + const mutexRelease = await this.manager._mutex.acquire() try { await this._prepare() await this._send() @@ -105,7 +105,7 @@ class Transaction { this.manager._nonce = this.tx.nonce + 1 return receipt } finally { - this.manager._mutex.release() + mutexRelease() } } diff --git a/test/TxManager.test.js b/test/TxManager.test.js index a8e461e..cd1224d 100644 --- a/test/TxManager.test.js +++ b/test/TxManager.test.js @@ -101,5 +101,23 @@ describe('TxManager', () => { console.log('receipt', receipt) }) + it.only('should send multiple txs', async () => { + const genTx = value => ({ + value, + to: '0x0039F22efB07A647557C7C5d17854CFD6D489eF3', + }) + await Promise.all([ + manager.createTx(genTx(1)).send(), + manager.createTx(genTx(2)).send(), + manager.createTx(genTx(3)).send(), + manager.createTx(genTx(4)).send(), + manager.createTx(genTx(5)).send(), + manager.createTx(genTx(6)).send(), + manager.createTx(genTx(7)).send(), + manager.createTx(genTx(8)).send(), + manager.createTx(genTx(9)).send(), + manager.createTx(genTx(10)).send(), + ]) + }) }) })