franciscop/translate

Why pending returning text?

Closed this issue · 1 comments

Hi, I was following your example and I wrote a very simple function to translate some text:

  async function trr(srcText) {
    const text = await translate(srcText, {from: "it", to: "en"});
    console.log(text);
  }

That's working perfectly. The problem is when I try to return the text translation to the calling function:

  async function trr(srcText) {
    const text = await translate(srcText, {from: "it", to: "en"});
    return text;
  }

When I call my trr() function and try to console.log the return text:

   const trans = trr(srcText);
   console.log(trans);

I get Promise {<pending>}
Why? What's wrong in my code?
Thank in advance you for your help.

You need to await on your promise/async code:

   const trans = await trr(srcText);
   console.log(trans);