0

Hi i use typescript for VSTS task extension, i created a function to get the json response from 3rd party server.

async function onlineChecker(projectName:string,checkerName:string){
let endPoint=getEndPoint();
let authHeader=getBasicAuthHeader();

let restClient:rm.RestClient=new rm.RestClient(endPoint);

let options:rm.IRequestOptions=<rm.IRequestOptions>{};
let headers:ifm.IHeaders=options.additionalHeaders||{};
headers["Authorization"]=authHeader;
let res: rm.IRestResponse<boolean>=await restClient.get<boolean>(endPoint,options)

return res;

}

I have another async function but calling to that function is based on value return from first function. How to make calls sync with these async functions or any other approach for this problem?

Nitin Parashar
  • 227
  • 3
  • 13

1 Answers1

0

You can add if statement before calling the second function.

You can get the value from your first function, and then add if statement to check if the value returned by the first function meet your requirement, if yes, call the second function.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • Its fine, but what happens when i have to wait for response in a while loop means i have to get the response from an api in a while loop, in async it create multi thread operations which result in heap full error – Nitin Parashar Jan 17 '18 at 11:58
  • You can use promise in async functuion. And you can also refer https://stackoverflow.com/questions/43064719/javascript-asynchronous-method-in-while-loop and https://developers.google.com/web/fundamentals/primers/async-functions. – Marina Liu Jan 18 '18 at 06:11