user14333765
user14333765

Reputation:

Async function returns Promise <Pending> instead of a value

Trying to log rs which should be the value of the function create order but it returns promise pending

let createOrder = async function () {
  let response = await client.execute(request);

  return response
};

let rs = createOrder().then((result) => console.log(result))

console.log("rsssss",rs)

Upvotes: 0

Views: 7687

Answers (1)

Jone Polvora
Jone Polvora

Reputation: 2338

You are not following the correct code pattern to handle async/Promises. When you're chaining methods, the promise is resolved inside the callback, not outside.

The return of .then() method is a promise object.

The correct code is this:


let createOrder = async function () { 
  let response = await client.execute(request);
  return response 
};

createOrder().then((result)=> {
  //the promise is resolved here
  console.log(result)
}).catch(console.error.bind(console))

Upvotes: 1

Related Questions