I have the following code:
import Web3 from 'web3';
function waitForFunds() {
let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
return new Promise((resolve, reject) => {
web3.eth.subscribe('pendingTransactions').on("data", resolve);
});
};
(async function () {
await waitForFunds();
console.log('Waiting');
})();
I would expect that nodeJS waits until the promise returned by waitForFunds() gets resolved, but instead, NodeJS is just exiting immediately and not waiting for the subscription to resolve the promise upon receiving data. The console never logs "Waiting". Am I doing anything wrong?