fix mutex

This commit is contained in:
Roman Storm 2021-02-16 22:08:12 -08:00
parent af7c597af9
commit f6a4e93a23
No known key found for this signature in database
GPG Key ID: 522F2A785F34E71F
2 changed files with 20 additions and 2 deletions

@ -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()
}
}

@ -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(),
])
})
})
})