Kotlinify LinearCountingRetryPolicy (#43871)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43871

Changelog: [Internal]

As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)).

Reviewed By: alanleedev

Differential Revision: D55753695

fbshipit-source-id: 4a46b02b2dd18981968371a94d2fa07af90fc74e
This commit is contained in:
Fabrizio Cucci
2024-04-05 14:14:06 -07:00
committed by Facebook GitHub Bot
parent 7cffdf2d73
commit efb00077ae
3 changed files with 32 additions and 49 deletions
@@ -2899,7 +2899,7 @@ public abstract interface class com/facebook/react/jstasks/HeadlessJsTaskRetryPo
public abstract fun update ()Lcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy;
}
public class com/facebook/react/jstasks/LinearCountingRetryPolicy : com/facebook/react/jstasks/HeadlessJsTaskRetryPolicy {
public final class com/facebook/react/jstasks/LinearCountingRetryPolicy : com/facebook/react/jstasks/HeadlessJsTaskRetryPolicy {
public fun <init> (II)V
public fun canRetry ()Z
public fun copy ()Lcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy;
@@ -1,48 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.jstasks;
import com.facebook.infer.annotation.Nullsafe;
@Nullsafe(Nullsafe.Mode.LOCAL)
public class LinearCountingRetryPolicy implements HeadlessJsTaskRetryPolicy {
private final int mRetryAttempts;
private final int mDelayBetweenAttemptsInMs;
public LinearCountingRetryPolicy(int retryAttempts, int delayBetweenAttemptsInMs) {
mRetryAttempts = retryAttempts;
mDelayBetweenAttemptsInMs = delayBetweenAttemptsInMs;
}
@Override
public boolean canRetry() {
return mRetryAttempts > 0;
}
@Override
public int getDelay() {
return mDelayBetweenAttemptsInMs;
}
@Override
public HeadlessJsTaskRetryPolicy update() {
final int remainingRetryAttempts = mRetryAttempts - 1;
if (remainingRetryAttempts > 0) {
return new LinearCountingRetryPolicy(remainingRetryAttempts, mDelayBetweenAttemptsInMs);
} else {
return NoRetryPolicy.INSTANCE;
}
}
@Override
public HeadlessJsTaskRetryPolicy copy() {
return new LinearCountingRetryPolicy(mRetryAttempts, mDelayBetweenAttemptsInMs);
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.jstasks
public class LinearCountingRetryPolicy(
private val retryAttempts: Int,
private val delayBetweenAttemptsInMs: Int
) : HeadlessJsTaskRetryPolicy {
override public fun canRetry(): Boolean = retryAttempts > 0
override public fun getDelay(): Int = delayBetweenAttemptsInMs
override public fun update(): HeadlessJsTaskRetryPolicy {
val remainingRetryAttempts = retryAttempts - 1
return if (remainingRetryAttempts > 0) {
LinearCountingRetryPolicy(remainingRetryAttempts, delayBetweenAttemptsInMs)
} else {
NoRetryPolicy.INSTANCE
}
}
override public fun copy(): HeadlessJsTaskRetryPolicy =
LinearCountingRetryPolicy(retryAttempts, delayBetweenAttemptsInMs)
}