Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda