I have a function that call a client and get data back and returns it:
const remoteConnection = await
this.client.connectionStatus(chassi, number, language) || [];
return {
data: remoteConnection as RemoteInfo,
read: new Date()
};
The response will be in this form:
{
connectionStatus: "",
online: ""
}
connectionStatus can have three states:
'disconnected'
'pending'
'connected'
I want to call my API and send the data. IF 'connectionStatus' is 'pending', I want to call the API every 5s to check if it changes to 'connected'. In that case, I want to return the data again with the new values.
In a nutshell:
Make API call and return the data. If 'connectionStatus' in the return data is equal to 'pending', make a new call every 5s to check if 'connectionStatus' is equal to 'connected'. If true, return data again.
How to do it?