Return value from javascript function callback using gRPC

Viewed 35

Im quite new on JS and it is hard for me to understand callbacks and functions, i just need to invoke that function that is a gRPC callback from a backend.

So, inside that "console.log(pararetornar) i get the correct value, i just need to send it out to the main code, on the image you can see "OUT HERE", i tried with a return but it wont work.

Any help is welcome, thanks

rl.question("Buscar por keyword: ? ", function (name) {
let dato = {
    site: [name],
};
let ret;
const resultado = existe(name);
(async () => {
    ret = await resultado;

    if (ret === true) {
        console.log("entre");
        getSitioBy(name);
    } else {
        console.log("hola:" + name);
        let send = { site: [] };
        send.site.push(name);
        client.searchByWord({ send }, (error, site) => {
            if (!error) {
                let pararetornar = "";
                values = site.array;
                values.forEach(function (item) {
                    pararetornar = item;
                });
                console.log(pararetornar); // I WANT TO SEND THIS VALUE - PARARETORNAR
            } else console.log(error);
        });

        **// OUT HERE**
        console.log(respuesta2);
        //setValue(name, JSON.stringify(query));
    }
})();

});

0 Answers
Related