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

171
Visualizações
How can I recreate a client and re-run automatically?

I have some code that looks like the following

const opts = {username: ..., password: ..., <misc>}
const client = new tmi.client(opts)

client.on('message', onMessageHandler)
client.on('connected', onConnectedHandler)

client.connect()

function onMessageHandler(props) {
    client.doStufF()
}

Basically, the code listens to an IRC chat and does stuff when a message comes through. Now, the code can fail on the .connect() and and on the .doStuff(), if the authentication expires. There is an API I can call with my saved refresh token to generate a new password, but right now I do this manually. I want to do this automatically.

The problem is, I'm not sure how to think about this pattern. Basically, I only know the token has expired once I make the call with invalid creds. But even if I write an error handler that catches the invalid credentials issue, how do I "go back" through all this code again to regenerate a new client with the new credentials and register the handlers again? I know this is a solved problem conceptually cause other packages offer this functionality already. I just want to implement it myself.

about 4 years ago · Santiago Gelvez
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