-1

when I call the following function like this:

  const data1 = async () => {
  const res = await server.fetch({ query: LISTINGS });
  return res;
  };
  console.log(data1());

It's console logging "Promise {<pending}" but when I change it to following function I get the response in console.

  const data1 = async () => {
  const res = await server.fetch({ query: LISTINGS });
  console.log(res);
  };
  data1();

what's the reason to Promise {<pending} behavior?

pasindu229
  • 17
  • 6

1 Answers1

3

Asynchronous functions return promises.

In fact, returning await inside async is really useless because you still get the promise when logging the return value. In the first example, the async function returns a promise containing the unwrapped value.

In the second example, your function is only called, and will log the unwrapped value to the console.