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

235
Views
How to properly return a value from a callback within a Promise?

I know that very similar questions have been asked, but I can't find one that fits my issue exactly- feel free to point me that way if there is one.

sendSteamAuthTicket: () => {
    return new Promise((resolve, reject) => {
        greenworks.getAuthSessionTicket(function(ticket) {
            console.log('Successfully retrieved Steam API User Auth Ticket.')
            console.log(ticket.ticket.toString('hex'))
            resolve(ticket.ticket.toString('hex'))
        }, function(e) { throw e })
    })
}

Basically, this returns an endlessly pending Promise, leading me to believe I can't resolve a Promise from within a nested callback like this. Unfortunately, I can't send the data via an additional function because electron won't let you interface with the browser that way.

Is it possible to do what I'm trying to do here? e.g. more or less obtain a delayed Promise value within this single function?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Alright, I figured it out- sorry for the redundant question, I've been banging my head on this for a few hours. Hearing that the Promise syntax was correct was apparently enough to get it through.

The greenworks package was being imported incorrectly (or, rather, correctly- according to their docs- but needed a direct file path)

It's a little outdated so I wasn't sure why at first.

about 4 years ago · Juan Pablo Isaza Report

0

There's nothing wrong with the way that you're calling resolve. If the callback is called, resolve will be, too, unless ticket is null or similar. My guess would be that greenworks is calling the error callback and then not re-throwing your thrown error. Try doing reject(e) instead of throw e.

about 4 years ago · Juan Pablo Isaza Report
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!