From e36baddff79da64a725ce9a52522e2b3c236cccc Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Thu, 4 Apr 2024 12:33:18 -0700 Subject: [PATCH] Kotlinify NoRetryPolicy (#43831) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43831 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: cortinico Differential Revision: D55708871 fbshipit-source-id: c557743bf35cd27559fe8365025ca071bef57701 --- .../facebook/react/jstasks/NoRetryPolicy.java | 39 ------------------- .../facebook/react/jstasks/NoRetryPolicy.kt | 28 +++++++++++++ 2 files changed, 28 insertions(+), 39 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.java deleted file mode 100644 index df4ca841fd5..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.java +++ /dev/null @@ -1,39 +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) -class NoRetryPolicy implements HeadlessJsTaskRetryPolicy { - - public static final NoRetryPolicy INSTANCE = new NoRetryPolicy(); - - private NoRetryPolicy() {} - - @Override - public boolean canRetry() { - return false; - } - - @Override - public int getDelay() { - throw new IllegalStateException("Should not retrieve delay as canRetry is: " + canRetry()); - } - - @Override - public HeadlessJsTaskRetryPolicy update() { - throw new IllegalStateException("Should not update as canRetry is: " + canRetry()); - } - - @Override - public HeadlessJsTaskRetryPolicy copy() { - // Class is immutable so no need to copy - return this; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.kt new file mode 100644 index 00000000000..df245683fd8 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jstasks/NoRetryPolicy.kt @@ -0,0 +1,28 @@ +/* + * 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 + +internal class NoRetryPolicy private constructor() : HeadlessJsTaskRetryPolicy { + + override public fun canRetry(): Boolean = false + + override public fun getDelay(): Int { + throw IllegalStateException("Should not retrieve delay as canRetry is: ${canRetry()}") + } + + override public fun update(): HeadlessJsTaskRetryPolicy { + throw IllegalStateException("Should not update as canRetry is: ${canRetry()}") + } + + // Class is immutable so no need to copy + override public fun copy(): HeadlessJsTaskRetryPolicy = this + + public companion object { + @JvmField public val INSTANCE: NoRetryPolicy = NoRetryPolicy() + } +}