Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda