Instead of returning Promise object i am getting resolved value. How is it happend? i am confused

Issue

This Content is from Stack Overflow. Question asked by Nehal Gupta

Actually i was going through Promise workflow then figured out something which left me confused….Please suggest with you opinions…

Code Below:

function GetAllListofEmployees()
{
  const promise = new Promise(function(resolve, reject){
    Url = 'api/GetEmployees';
    ServiceInstance.GetCall(Url).then(function (result){
      //from result Load Data to global variable;
      resolve("Yes");  
  })  
})
}

async function ShowEmployees()
{
   var promise = await GetAllListofEmployees();// this line is returning me 'Yes' instead of   
                                                  a promise object, without applying '.then' 
                                                  function and call resolve function to get  
                                                  the value.
   if(promise == "Yes") 
   {
     // i can access this block causing result is "Yes".
   }

}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?