Skip to content

Commit a50c63f

Browse files
gaodengKrzysztof Borowy
authored and
Krzysztof Borowy
committed
feat: Custom Executor for Android
1 parent 8a19568 commit a50c63f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ if( newDbSize != null && newDbSize.isLong()) {
3030
dbSizeInMB = newDbSize.toLong()
3131
}
3232

33+
def useCustomExecutor = rootProject.hasProperty('AsyncStorage_useCustomExecutor')
34+
? rootProject.properties['AsyncStorage_useCustomExecutor']
35+
: false
36+
3337
apply plugin: 'com.android.library'
3438

3539
android {
@@ -41,6 +45,7 @@ android {
4145
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
4246

4347
buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
48+
buildConfigField("boolean", "AsyncStorage_useCustomExecutor", "${useCustomExecutor}")
4449
}
4550
}
4651

android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.ArrayDeque;
3030
import java.util.HashSet;
3131
import java.util.concurrent.Executor;
32+
import java.util.concurrent.Executors;
3233

3334
@ReactModule(name = AsyncStorageModule.NAME)
3435
public final class AsyncStorageModule
@@ -78,7 +79,12 @@ synchronized void scheduleNext() {
7879
private final SerialExecutor executor;
7980

8081
public AsyncStorageModule(ReactApplicationContext reactContext) {
81-
this(reactContext, AsyncTask.THREAD_POOL_EXECUTOR);
82+
this(
83+
reactContext,
84+
BuildConfig.AsyncStorage_useCustomExecutor
85+
? Executors.newSingleThreadExecutor()
86+
: AsyncTask.THREAD_POOL_EXECUTOR
87+
);
8288
}
8389

8490
@VisibleForTesting

0 commit comments

Comments
 (0)