Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
How to make NodeJS wait until a promise gets resolved inside a subscription?

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!