0
let CountryGobObj = {
  "CountryName": "",
  "CurrencySymbol": "",
  "CurrencyConverter": ""
};
HttpService.country().then(response => {
  // const CountryDet = response.data;
  let CountryObj = {};
  const CountryName = response.data.geoplugin_countryName;
  const CurrencySymbol = response.data.geoplugin_currencySymbol;
  const CurrencyConverter = response.data.geoplugin_currencyConverter;
  CountryObj.CountryName = CountryName
  CountryObj.CurrencySymbol = CurrencySymbol
  CountryObj.CurrencyConverter = CurrencyConverter
  console.log('1', CountryObj);
  CountryGobObj = CountryObj;
  console.log('2', CountryGobObj);
});
console.log('3', CountryGobObj);
return CountryGobObj;

it is executing in a order of 3 1 2 But I want 1 2 3 in a order can you please help me out

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Everything that should wait for `country()` to finish should be in the `then()` callback function. – Barmar Nov 24 '20 at 06:54
  • Try to make this function [`async`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) and use `await` to wait for the result. – Hao Wu Nov 24 '20 at 06:54
  • unable to add async before the HttpService –  Nov 24 '20 at 07:02

0 Answers0