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

159
Visualizações
Extending a promise leads to "Promise resolve or reject function is not callable" when attempting to await it
class ControllablePromise extends Promise {
    constructor() {
        let resolveClosure = null;
        let rejectClosure = null;
        super((resolve, reject) => {
            resolveClosure = resolve;
            rejectClosure = reject;
        });

        this.resolveClosure = resolveClosure;
        this.rejectClosure = rejectClosure;
    }
}
const prom = new ControllablePromise();

async function func(){
  try{
    await prom;
    console.log('done');
  }
  catch(err){
    console.log(err.message);
  }
}


setTimeout(() => {prom.rejectClosure(); console.log('resolved');}, 1000);
func();

I am attempting to create a promise that I can resolve/reject externally. I can do this functionally without issue, just returning a regular promise after I attach the resolve/reject closures to it, but when attempting to turn it into a class I am running into difficulty. The code above throws an error when attempting to await the promise. Why is this happening exactly?

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