Dialog in function to block function call and wait for user response?

Dialog in function to block function call and wait for user response?


I want to see if there's any recipes to wrte something like this:
function getResponse() {
$('#dialog').dialog(...);
// now function block up here
return $('#dialog').find('control').val();
}
basically I want the dialog works really like a modal dialog to block
the function until it comes back. I can think of something really
looks a bit stupid- a loop with a idle timeout checking the isOpen
status for the dialog. However I would like to see if there is anybody
did something better for it already :)
Thanks for help.