I have written a function that allows me to send an arbitrary amount of transactions, asynchronously, to my smart contract. However the process stays open even after the last transaction has finished. Currently, I have to manually press CTRL+C to exit. I would like for my program to automatically exit once the last transaction has finished. How would I go about doing this?
async function multipleTx(n) {
accounts = await web3.eth.getAccounts()
let totalGasUsed = 0
for (let i = 0; i < n; i++) {
instance.methods
.addSubmission(i, i, i, i)
.send({
from: accounts[0],
gasPrice: 10000000000,
})
.then((receipt) => {
console.log(receipt)
totalGasUsed += receipt.gasUsed
console.log(totalGasUsed)
})
}
}