I don't know if it is possible, but I really want to force a normal function to stop and wait for a async function. Here is a simple example:
function draw_a_cat(){
draw_cat_body();
// get_head_information is asynchronous, and I want to STOP execution and wait for it to get info we need in order to draw the cat.
wait for get_head_information();
draw_head();
display_cat_name();
return true;
}
cat_drawn_yet = draw_a_cat();
console.log("drawn")!
I am not actually working on drawing cats, but I need to know how to do this. I wan't draw_a_cat
to wait for get_head_information
, meaning draw_cat
will not return until it has gotten the head information and drawn the head. The head won't be drawn until the head information has been obtained, so that we can draw the head correctly.
And, the console.log
won't happen until the cat is fully drawn and cat_drawn_yet == "true"
. draw_a_cat
is not an async function, meaning it cannot just await get_head_information()
.
I want the program to stop and wait for the async get_head_information
before continuing normally. I know it sounds stupid to freeze everything else, waiting for get_head_information
, but I need to do this in a more complicated project where it just makes sense.