I'm facing an issue with making two API calls concurrently. The goal is to have call X executed first, while Y should run in parallel and keep calling itself recursively until the X API resolves. Both calls should be initiated immediately upon clicking a button.
function X () {
return new Promise((resolve,reject) => {
Service.requestAPI(RequestMethod.GET, API_URL.validateProductStatus)
.then(response => {
resolve(response)
}
}
}
function Y () {
Service.requestAPI(RequestMethod.GET, API_URL.validateProductStatus)
.then(response => {
if(response){
setTimeout(() => {
this.onStatusChange()
},1000)
}
}
}
async function buttonCLick() {
const XResponse = await X();
Y();
}
The current implementation is not working as expected. The second call, Y, is being treated as a synchronous call instead of asynchronous. What could be causing this issue?