How to get the result of a callback function before continuing the main function?

I use a recursive function to construct a JSON data containing (URL, children, data). I send this data to my graph (RGraph library) in order to create it. The problem is that in my function creer_json = (url, nom, recursif, recursif_max) I have a problem. Here's the code :

creer_json = (url, nom, recursif, recursif_max) ->
recursif--
resultat = {}
@tab = []
tableau = getBody(url,(error,message) ->
    @tab = getTab(message.body))
tab_children = []
tab_relation = []
indice = 0
id_enfant = 1
adresse = "<h1>Liens de "+url+"</h1>"
while indice < tab.length
    if (recursif == recursif_max-1)
        id_urlfils = id_enfant
    else
        id_urlfils = nom+"."+id_enfant
    adresse = adresse+" "+"<li>"+id_urlfils+" : "+"<a href="+tab[indice]+">"+tab[indice]+"</a></li>"
    indice++
    id_enfant++
tab_relation.push("<ul>"+adresse+"</ul>")
id_url = 1
i = 0
while i < tab.length
    if (recursif == recursif_max-1)
        id_urlfils = id_url
    else
        id_urlfils = nom+"."+id_url
    if recursif >= 0
        json2 = creer_json(tab[i], id_urlfils, recursif, recursif_max)
        tab_children.push(json2)
    i++
    id_url++
resultat = 
    id : nom
    name : nom
    children : tab_children
    data : { relation: tab_relation }
return resultat

My problem is that i need the result of the fourth instruction to continue the main function :

tableau = getBody(url,(error,message) ->
    @tab = getTab(message.body))

@tab contains all the URL of a website and i have to loop on them to construct the JSON data. The main function continue without the result of @tab and I NEED that data! My problem may not be clear so don't hesitate to ask me if you don't understand. Thank you in advance for your time.

As Eru wrote: If you need the result of an asynchronous call, you have to continue in the callback. You can’t re-synchronize an async call. This also means that you can’t return anything useful from creer_json. Instead, if you need the return value, you have to add a callback parameter which gets the return value passed. What’s more, since creer_json would become an asynchronous function and you call it recursively, these recursive calls would need to be with callbacks.