Consider below code snippet. Too many take() calls will result in stack overflow error. What is the good strategy to overcome such scenarios?
def take(): Future[Int] = {
val processResponseF: Future[Boolean] = performSomeAction()
processResponseF.flatMap(
processResponse => {
if(processResponse)
Future.successful(100)
else
take()
}
)
}
def performSomeAction(): Future[Boolean] = {
//This returns future of boolean
}
Assumption - 1. Method signature should not be changed