fun execute()

in android/src/main/java/com/google/recaptchaenterprisereactnative/RecaptchaEnterpriseReactNativeModule.kt [93:123]


  fun execute(actionStr: String, arguments: ReadableMap, promise: Promise) {
    if (!this::recaptchaClient.isInitialized) {
      promise.reject("RN_EXECUTE_FAILED", "Initialize client first", null)
      return
    }
    
    val action = mapAction(actionStr)
    
    GlobalScope.launch {
      recaptchaClient
      .let {
        if (arguments.hasKey("timeout")) {
          // JS+ReadableMap have no support for long
          val timeout = arguments.getDouble("timeout").toLong()
          it.execute(action, timeout)
        } else {
          it.execute(action)
        }
      }
      .onSuccess { token ->
        promise.resolve(token)
      }
      .onFailure { exception ->
        if (exception is RecaptchaException) {
          promise.reject(exception.errorCode.toString(), exception.errorMessage, exception)
        } else {
          promise.reject(exception)
        }
      }
    }
  }