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

150
Vistas
JS - send WS message, wait for response, then send again depending on the response (all inside one function)

My goal is to, in one function, send a ws message: ws.send(message),then wait for server response, which is handled by ws.onmessage = async (event) => - and depending on the server answer, send next message inside the same function

The problem is that I cannot receive response from the server before leaving the function. What tool would be the best to use in this case? (Im still at begginer level in JS)

Full code of the function is:

function ComboAction(data){
    ws.send('message1')
    //here i want to wait for server's response and continue this function depending on the response.
    //wait for server response?
    ws.send('message depending on server response to first message')
}

I was wondering out with promises? or the => method, but it's out of my reach for now. Any tips will be greatly appreciated!

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