Hi All,
I have one question, I am trying to fetch people profile for a given mobile number from redis. There could be multiple profile for a mobile number and at a time only one could be the active or none. I need to return the optional of empty or option of profile but I always getting failure due to async nature, what could be the possible solution
I have written something like this
public Future<Optional<Profile>> returnProfile(Set<String> profileNumber){
Promise<LinkageResponseDto> linkageResponseDtoPromise = Promise.promise();
AtomicBoolean isActive = new AtomicBoolean();
int indexOfProfileNumber = 0;
while(indexOfProfileNumber < profileNumber.size()){
redisApi
.hgetall(key)
.onSuccess(peopleProfile->
{
var
peopleProfile
= convertToPeopleProfile(peopleProfile.toString());
if(peopleProfile.isActive()){
linkageResponseDtoPromise.complete(peopleProfile)
isActive.set(true);
}
});
}
if(!isActive.get()){
//complete or fail
linkageResponseDtoPromise.fail(“Not active profile”);
}
return linkageResponseDtoPromise.future();
}