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

138
Visualizações
Do I need to keep a reference to a JS promise chain?

In modern Javascript, if I build up a sequence of actions inside promise.then(...).catch(...), but I don't care about the result, nor do I need to wait for the sequence to finish, but I do want it to finish, do I need to keep a reference to the resulting Promise? Is there a danger that it might be garbage-collected and never run to completion if I don't keep a reference to it alive?

If the answer is "this is implementation-dependent," that's disappointing. But I'd be especially interested to know how recent versions of V8 (≥ 9.5) handle this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Do I need to keep a reference to a JS promise chain?

No, you do not. The promise chain will run to completion whether you save the promise or not.

Things are only garbage collected when they are no longer referenced by any active code. A promise that represents an active asynchronous operation is still being referenced by that asynchronous operation until that asynchronous operation is actually complete (since the asynchronous operation has the ability to resolve or reject the promise). So, promises won't be eligible for garbage collection until the operations they are connected to are done.

This is not implementation-dependent. The garbage collector cannot collect objects that are still in use. Everything would break if that was the case. Once the promise is no longer in use, then garbage collecting it has no affect on any running code.

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