Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!