i'm making a javascript widget (for the thingsboard platform). the thingsboard site has some javascript code running (e.g. do_some_things
) which i can not modify. my widget can define functions like func_1
that will be run by the thingsboard site.
//### THINGSBOARD CODE (can not modify!) ###
function do_some_things() {
...
func_1();
func_2();
...
}
//### WIDGET CODE (can modify!) ###
function func_1() {
socket = new WebSocket("ws://192.168.137.4:8081/");
socket.onmessage=function(evt) {
settings_string = evt.data;
}
/* wait for a message here!*/
return settings_string;
}
in func_1
i would like to return some string that i retrive from a websocket server. how do i block the execution of func_1
until i have the websocket message?
i've had a look at promises and await, but i don't see how that can help me as i cant allow func_2
to run before func_1
is done and has returned its value.
(i don't care if the whole site freezes while it's waiting for the websocket)