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!