He-Pin commented on code in PR #1269: URL: https://github.com/apache/pekko/pull/1269#discussion_r1554576824
########## actor/src/main/scala/org/apache/pekko/pattern/RetrySupport.scala: ########## @@ -172,30 +175,34 @@ object RetrySupport extends RetrySupport { } } - require(maxAttempts >= 0, "Parameter maxAttempts must >= 0.") + def doRetry(nextAttempt: Int): Future[T] = delayFunction(nextAttempt) match { + case Some(delay) => + if (delay.length < 1) + retry(attempt, maxAttempts, delayFunction, nextAttempt, shouldRetry) + else + after(delay, scheduler) { + retry(attempt, maxAttempts, delayFunction, nextAttempt, shouldRetry) + } + case None => + retry(attempt, maxAttempts, delayFunction, nextAttempt, shouldRetry) + case null => + Future.failed(new IllegalArgumentException("The delayFunction of retry should not return null.")) + } + require(attempt != null, "Parameter attempt should not be null.") + require(maxAttempts >= 0, "Parameter maxAttempts must >= 0.") + require(delayFunction != null, "Parameter delayFunction should not be null.") + require(attempted >= 0, "Parameter attempted must >= 0.") + if (maxAttempts - attempted > 0) { val result = tryAttempt() if (result eq null) result else { - val nextAttempt = attempted + 1 - result.recoverWith { - case NonFatal(_) => - delayFunction(nextAttempt) match { - case Some(delay) => - if (delay.length < 1) - retry(attempt, maxAttempts, delayFunction, nextAttempt) - else - after(delay, scheduler) { - retry(attempt, maxAttempts, delayFunction, nextAttempt) - } - case None => - retry(attempt, maxAttempts, delayFunction, nextAttempt) - case null => - Future.failed(new IllegalArgumentException("The delayFunction of retry should not return null.")) - } - + result.transformWith { + case Success(value) if shouldRetry(value, null) => doRetry(attempted + 1) + case Failure(e) if NonFatal(e) && shouldRetry(null.asInstanceOf[T], e) => doRetry(attempted + 1) + case _ => result Review Comment: Should I change the code to `isInstanceOf` and `asInstanceOf` for performance? Still need more time to finish this PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For additional commands, e-mail: notifications-h...@pekko.apache.org