@functionland/react-native-fula 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,8 @@ import java.util.concurrent.Executors;
25
25
  import java.util.concurrent.ScheduledExecutorService;
26
26
  import java.util.concurrent.TimeUnit;
27
27
  import java.util.concurrent.atomic.AtomicBoolean;
28
+ import java.util.concurrent.Future;
29
+ import java.util.concurrent.TimeoutException;
28
30
 
29
31
  import org.json.JSONObject;
30
32
  import org.json.JSONArray;
@@ -263,42 +265,50 @@ public class FulaModule extends ReactContextBaseJavaModule {
263
265
 
264
266
  private boolean checkConnectionInternal(int timeout) throws Exception {
265
267
  try {
266
- Log.d("ReactNative", "checkConnectionInternal started");
267
- if (this.fula != null) {
268
+ Log.d("ReactNative", "checkConnectionInternal started");
269
+ if (this.fula != null) {
270
+ try {
271
+ Log.d("ReactNative", "connectToBlox started");
272
+
273
+ AtomicBoolean connectionStatus = new AtomicBoolean(false);
274
+ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
275
+ Future<?> future = executor.submit(() -> {
268
276
  try {
269
- Log.d("ReactNative", "connectToBlox started");
270
-
271
- AtomicBoolean connectionStatus = new AtomicBoolean(false);
272
- ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
273
- executor.schedule(() -> {
274
- try {
275
- this.fula.connectToBlox();
276
- connectionStatus.set(true);
277
- Log.d("ReactNative", "checkConnectionInternal succeeded ");
278
- } catch (Exception e) {
279
- Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
280
- }
281
- }, 0, TimeUnit.SECONDS);
282
-
283
- executor.schedule(() -> {
284
- executor.shutdown();
285
- }, timeout, TimeUnit.SECONDS);
286
-
287
- executor.awaitTermination(timeout, TimeUnit.SECONDS);
288
- return connectionStatus.get();
277
+ this.fula.connectToBlox();
278
+ connectionStatus.set(true);
279
+ Log.d("ReactNative", "checkConnectionInternal succeeded ");
289
280
  } catch (Exception e) {
290
- Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
291
- return false;
281
+ Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
292
282
  }
293
- } else {
294
- Log.d("ReactNative", "checkConnectionInternal failed because fula is not initialized ");
283
+ });
284
+
285
+ try {
286
+ future.get(timeout, TimeUnit.SECONDS);
287
+ } catch (TimeoutException te) {
288
+ // If the timeout occurs, shut down the executor and return false
289
+ executor.shutdownNow();
295
290
  return false;
291
+ } finally {
292
+ // If the future task is done, we can shut down the executor
293
+ if (future.isDone()) {
294
+ executor.shutdown();
295
+ }
296
+ }
297
+
298
+ return connectionStatus.get();
299
+ } catch (Exception e) {
300
+ Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
301
+ return false;
296
302
  }
303
+ } else {
304
+ Log.d("ReactNative", "checkConnectionInternal failed because fula is not initialized ");
305
+ return false;
306
+ }
297
307
  } catch (Exception e) {
298
- Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
299
- throw (e);
308
+ Log.d("ReactNative", "checkConnectionInternal failed with Error: " + e.getMessage());
309
+ throw (e);
300
310
  }
301
- }
311
+ }
302
312
 
303
313
  @ReactMethod
304
314
  private void checkFailedActions(boolean retry, int timeout, Promise promise) throws Exception {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionland/react-native-fula",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -28,7 +28,7 @@
28
28
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
29
29
  "prepare": "bob build",
30
30
  "release": "release-it",
31
- "example": "set NODE_OPTIONS=--openssl-legacy-provider && yarn --cwd example",
31
+ "example": "set NODE_OPTIONS='' && yarn --cwd example",
32
32
  "pods": "cd example && pod-install --quiet",
33
33
  "bootstrap": "yarn example && yarn && yarn pods"
34
34
  },