mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 17:39:48 +08:00
Reviewed By: andreicoman11 Differential Revision: D2679459 fb-gh-sync-id: 8a9ec170ce76bbc3340c9e8872e19b78ae5a5c2d
44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
package com.facebook.react.bridge;
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
/**
|
|
* Abstract base for a AsyncTask with result support that should have any RuntimeExceptions it
|
|
* throws handled by the {@link com.facebook.react.bridge.NativeModuleCallExceptionHandler}
|
|
* registered if the app is in dev mode.
|
|
*/
|
|
public abstract class GuardedResultAsyncTask<Result>
|
|
extends AsyncTask<Void, Void, Result> {
|
|
|
|
private final ReactContext mReactContext;
|
|
|
|
protected GuardedResultAsyncTask(ReactContext reactContext) {
|
|
mReactContext = reactContext;
|
|
}
|
|
|
|
@Override
|
|
protected final Result doInBackground(Void... params) {
|
|
try {
|
|
return doInBackgroundGuarded();
|
|
} catch (RuntimeException e) {
|
|
mReactContext.handleException(e);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected final void onPostExecute(Result result) {
|
|
try {
|
|
onPostExecuteGuarded(result);
|
|
} catch (RuntimeException e) {
|
|
mReactContext.handleException(e);
|
|
}
|
|
}
|
|
|
|
protected abstract Result doInBackgroundGuarded();
|
|
protected abstract void onPostExecuteGuarded(Result result);
|
|
|
|
}
|