0

I have a function which should do something with a promise (returned from another function) and return a value, which should not be a promise.

How can I do that without converting it into a async function?
Is it possible to do it with a generator? Thanks

function (intents, entities, resObject) {
    let output = [];
    ...

    output[0]= "test"

    //returns a promise
    var res = dbAccess.getFreeBaggage("IntercontEconomyLightFTL");

    let HBWeight = res[0].HBWeight;
    console.log("Result ", HBWeight, NumOfHB);*/

    output[1] = res[0].HBWeight;
    ...

    return output;
},
Neli
  • 532
  • 1
  • 3
  • 15
  • You cannot do that. – Quentin Jul 09 '18 at 14:55
  • if you don't want to use `async`/`await`, you can do it with an antique `setInterval`.. but it's a bit ugly to mix promises with that. Do you have a real reason not to use `async`/`await` or make your first function asynchronous by using callbacks for example? – Kaddath Jul 09 '18 at 15:08
  • Hello Kaddath. Thanks for your answer. How can I use setInterval, I only want to execute the function once? Unfortunately this function can not be async – Neli Jul 09 '18 at 15:13
  • that would be silly to complicate everything with `setInterval`. If you have the first part of your function where code is done before calling the promise, and a second part with the code to do after the promise is resolved, just split your function in 2 functions, and use the second as a callback for the promise – Kaddath Jul 09 '18 at 15:32
  • how can I use the second function as a callback for the promise? sorry, I'm a newby – Neli Jul 10 '18 at 06:20

0 Answers0