Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
const fetchData = async (crmManager) => {
  const response = await crmManager.getPayload();
  console.log(fetchDataresponse);
}

fetchData(); // object with data from CRM { name: 'Zalgiris', id: '19860815', ... }

Without await, you would get unfulfilled promise which doesn't have anything to return or show:

Code Block
languagejs
const fetchData = (crmManager) => {
  const response = crmManager.getPayload();
  console.log(fetchDataresponse);
}

fetchData(); // Promise<Pending>
// This happened because console.log accessed response
// while it is still being executed

Then

then is a method used to handle the resolution or rejection of a Promise by providing callback functions to be executed when the Promise is resolved or rejected, allowing for the chaining of asynchronous operations.

...