Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
android: pool calls happen in own thread (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Kenyon <[email protected]>
  • Loading branch information
TheTreek authored Dec 17, 2021
1 parent f058a5b commit 222b2d0
Showing 1 changed file with 59 additions and 43 deletions.
102 changes: 59 additions & 43 deletions android/src/main/java/com/reactlibrary/IndySdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,57 +426,73 @@ public void createPoolLedgerConfig(String configName, String poolConfig, Promise
}

@ReactMethod
public void openPoolLedger(String configName, String poolConfig, Promise promise) {
try {
if (poolNameToHandleMap.get(configName) != null){
promise.resolve(poolNameToHandleMap.get(configName));

} else {
Pool pool = Pool.openPoolLedger(configName, poolConfig).get();
poolMap.put(pool.getPoolHandle(), pool);
poolNameToHandleMap.put(configName, pool.getPoolHandle());
promise.resolve(pool.getPoolHandle());
public void openPoolLedger(final String configName, final String poolConfig, final Promise promise) {
new Thread(new Runnable(){
@Override
public void run() {
try {
if (poolNameToHandleMap.get(configName) != null){
promise.resolve(poolNameToHandleMap.get(configName));

} else {
Pool pool = Pool.openPoolLedger(configName, poolConfig).get();
poolMap.put(pool.getPoolHandle(), pool);
poolNameToHandleMap.put(configName, pool.getPoolHandle());
promise.resolve(pool.getPoolHandle());
}
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void closePoolLedger(int handle, Promise promise) {
try {
Pool pool = poolMap.get(handle);
pool.closePoolLedger().get();
poolMap.remove(handle);

// Remove pool id mapping
for (Map.Entry<String, Integer> entry : poolNameToHandleMap.entrySet()) {
if (entry.getValue().equals(handle)) {
poolNameToHandleMap.remove(entry.getKey());
break;
}, "openPoolLedger").start();
}

@ReactMethod
public void closePoolLedger(final int handle, final Promise promise) {
new Thread(new Runnable(){
@Override
public void run() {
try {
Pool pool = poolMap.get(handle);
pool.closePoolLedger().get();
poolMap.remove(handle);

// Remove pool id mapping
for (Map.Entry<String, Integer> entry : poolNameToHandleMap.entrySet()) {
if (entry.getValue().equals(handle)) {
poolNameToHandleMap.remove(entry.getKey());
break;
}
}

promise.resolve(null);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

promise.resolve(null);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}, "closePoolLedger").start();
}

// ledger

@ReactMethod
public void submitRequest(int poolHandle, String requestJson, Promise promise) {
try {
Pool pool = poolMap.get(poolHandle);
String response = Ledger.submitRequest(pool, requestJson).get();
promise.resolve(response);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
public void submitRequest(final int poolHandle, final String requestJson, final Promise promise) {
new Thread(new Runnable(){
@Override
public void run() {
try {
Pool pool = poolMap.get(poolHandle);
String response = Ledger.submitRequest(pool, requestJson).get();
promise.resolve(response);
} catch (Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

}, "submitRequest").start();
}

@ReactMethod
Expand Down

0 comments on commit 222b2d0

Please sign in to comment.