Skip to content

Commit c372dc1

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Migrate GuardedAsyncTask to Kotlin (facebook#50254)
Summary: Migrate com.facebook.react.bridge.GuardedAsyncTask to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.bridge.GuardedAsyncTask to Kotlin Pull Request resolved: facebook#50254 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: javache Differential Revision: D71846375 Pulled By: Abbondanzo fbshipit-source-id: e4befe99333512312d1930b09b1edd9501a2f80a
1 parent 9a5a679 commit c372dc1

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,18 @@ public class com/facebook/react/bridge/DynamicFromObject : com/facebook/react/br
727727
}
728728

729729
public abstract class com/facebook/react/bridge/GuardedAsyncTask : android/os/AsyncTask {
730+
public static final field Companion Lcom/facebook/react/bridge/GuardedAsyncTask$Companion;
731+
public static final field THREAD_POOL_EXECUTOR Ljava/util/concurrent/Executor;
730732
protected fun <init> (Lcom/facebook/react/bridge/JSExceptionHandler;)V
731733
protected fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
732-
protected synthetic fun doInBackground ([Ljava/lang/Object;)Ljava/lang/Object;
734+
public synthetic fun doInBackground ([Ljava/lang/Object;)Ljava/lang/Object;
733735
protected final fun doInBackground ([Ljava/lang/Object;)Ljava/lang/Void;
734736
protected abstract fun doInBackgroundGuarded ([Ljava/lang/Object;)V
735737
}
736738

739+
public final class com/facebook/react/bridge/GuardedAsyncTask$Companion {
740+
}
741+
737742
public abstract class com/facebook/react/bridge/GuardedRunnable : java/lang/Runnable {
738743
public fun <init> (Lcom/facebook/react/bridge/JSExceptionHandler;)V
739744
public fun <init> (Lcom/facebook/react/bridge/ReactContext;)V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/GuardedAsyncTask.java

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
@file:Suppress("DEPRECATION") // Need to migrate away from AsyncTasks
9+
10+
package com.facebook.react.bridge
11+
12+
import android.os.AsyncTask
13+
import java.util.concurrent.Executor
14+
15+
/**
16+
* Abstract base for a AsyncTask that should have any RuntimeExceptions it throws handled by the
17+
* [JSExceptionHandler] registered if the app is in dev mode.
18+
*
19+
* This class doesn't allow doInBackground to return a results. If you need this use
20+
* GuardedResultAsyncTask instead.
21+
*/
22+
public abstract class GuardedAsyncTask<Params, Progress>
23+
protected constructor(private val exceptionHandler: JSExceptionHandler) :
24+
AsyncTask<Params, Progress, Void>() {
25+
protected constructor(reactContext: ReactContext) : this(reactContext.exceptionHandler)
26+
27+
@Deprecated("AsyncTask is deprecated.")
28+
override protected final fun doInBackground(vararg params: Params): Void? {
29+
try {
30+
doInBackgroundGuarded(*params)
31+
} catch (e: RuntimeException) {
32+
exceptionHandler.handleException(e)
33+
}
34+
return null
35+
}
36+
37+
protected abstract fun doInBackgroundGuarded(vararg params: Params)
38+
39+
public companion object {
40+
@JvmField public val THREAD_POOL_EXECUTOR: Executor = AsyncTask.THREAD_POOL_EXECUTOR
41+
}
42+
}

0 commit comments

Comments
 (0)