You can have two functions for getting a callback. For example, you could take this or simular aproach, since javascript is Async lang.
Theoreticaly with this you could put your draw in callit function, and drop a callback after it, so it would call the other function to extend it.
callit(clb_extend, 'Steve');
function clb_extend(name) {
console.log('after 5 prints, Im called: '+name);
}
function callit(clb,smname) {
for(var i=0; i<5;i++) {
console.log('Look I am printing');
}
clb(smname);
}
So after 5 prints, it prints something that you told so, You could use this and avoid using pure sync, so the rest of the code still can run without thinking that he needs to finish that one first. otherwise, you could try using promises, and .then functions. You can read about it at similar question. How should I call 3 functions in order to execute them one after the other?