mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
Init in background thread
This commit is contained in:
@@ -259,6 +259,7 @@ function App(): JSX.Element {
|
||||
handleResponseAndroid(response);
|
||||
} catch (e: any) {
|
||||
console.log('error during scan :', e);
|
||||
setStep(Steps.MRZ_SCAN_COMPLETED);
|
||||
Toast.show({
|
||||
type: 'error',
|
||||
text1: e.message,
|
||||
|
||||
@@ -138,6 +138,7 @@ dependencies {
|
||||
}
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation("net.java.dev.jna:jna:5.13.0@aar")
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android'
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,14 @@ import com.facebook.react.bridge.ReactMethod
|
||||
import com.facebook.react.bridge.Promise
|
||||
|
||||
import android.util.Log
|
||||
|
||||
import com.facebook.react.bridge.ReadableMap
|
||||
|
||||
import uniffi.mopro.GenerateProofResult
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
||||
private val TAG = "ProverModule"
|
||||
lateinit var res: GenerateProofResult
|
||||
@@ -21,11 +25,24 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
||||
|
||||
@ReactMethod
|
||||
fun runInitAction(promise: Promise) {
|
||||
val startTime = System.currentTimeMillis()
|
||||
uniffi.mopro.initializeMopro()
|
||||
val endTime = System.currentTimeMillis()
|
||||
val initTime = "init time: " + (endTime - startTime).toString() + " ms"
|
||||
promise.resolve(initTime)
|
||||
// Launch a coroutine in the IO dispatcher for background tasks
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val startTime = System.currentTimeMillis()
|
||||
uniffi.mopro.initializeMopro()
|
||||
val endTime = System.currentTimeMillis()
|
||||
val initTime = "init time: " + (endTime - startTime).toString() + " ms"
|
||||
|
||||
// Since the promise needs to be resolved in the main thread
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.resolve(initTime)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.reject(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @ReactMethod
|
||||
|
||||
Reference in New Issue
Block a user