I have a function that gets information if an adapter is connected:
private registerAdapter() {
this.register(GetAdapter, Action.Get, async (): Promise<IData<AdapterInfo>> => {
await this.setup;
if (!this.myClient?.canGetAdapter()) {
return Promise.reject('My client is not able to get connected adapter');
}
const adapter = await this.myClient.getAdapter();
if (!adapter) {
return Promise.reject('My communication client is not able to get adapter');
}
return {
data: {
adapter
},
read: new Date()
};
});
}
Above will work, and I get the info if an adapter is connected. However, if the adapter is disconnected during runtime, the information will not be updated and it will still say "Connected".
I want, when the adapter is connected, return this information and then "observe" the service every 5s and if the response is null, return the new results. How to do that? Flow should be something like:
Service: adapter is connected, return data Observe every 5s for change in service Service: adapter is disconnected, return null Observer catches the change and the function will return null