2

I try to make the function wait for the Query result but I never get the result. I always have a Promise {Pending} and later the Query to Splunk Done is displayed. How do I make the program wait for the result?

I want to wait for the result and then send the result to a bot.

async function esperate () {
  var variable = splunk_normal(Query_splunk, () =>{
    console.log('Query to Splunk Done');
    //exports results from Splunk SDK
    const newLocal = myModule.resultados
    var results2 = newLocal;
    return results2;
  });

  console.log("one");
  return variable;
} 

var mirar = esperate();
console.log(variable);
kwoxer
  • 3,734
  • 4
  • 40
  • 70

1 Answers1

2

You need to add an await:

async function esperate ()
{
    var variable = splunk_normal(Query_splunk, () =>{ 
        console.log('Query to Splunk Done');

        //exports results from Splunk SDK
        const newLocal = await myModule.resultados // Here
        var results2 = newLocal;
        return results2;

    });
    console.log("one");

    return variable;
}

var mirar = esperate();
console.log(variable);
Andrés Muñoz
  • 559
  • 3
  • 8