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

130
Views
How to return PromiEvent from async function

I need to return PromiEvent (https://www.npmjs.com/package/web3-core-promievent) from async function. But I always got a common Promise without on handlers. Here is the test code: const Web3PromiEvent = require('web3-core-promievent')

async function sleep() {
    return new Promise((resolve) => setTimeout(resolve, 1000))
}

async function inner() {
    const pe = new Web3PromiEvent()

    await sleep()

    pe.eventEmitter.emit('done', 'ok')
    pe.resolve('ok')

    return pe
}

async function main() {
    const pe = inner()

    pe.on('done', console.log)

    const res = await pe
    console.log(res)
}

main()

Here the example in sandbox: https://codesandbox.io/s/node-js-forked-lw19bp?file=/src/index.js

How properly return PromiEvent from async function?

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!