I'm writing a web scraper, which looks like
function get_links(url){
    var links = new Array();
    get_page(url,function(page){
        links = parse_links(page);
    });
    return links;
}
while(true){
    var a = queue.pop_front();
    queue.push.apply(queue, get_links(a));
}
(the actual code contains other unrelated details, so I simplify it)
The problem is that, sometimes return is executed before the callback function, when links is still empty.
