|
24 | 24 | )
|
25 | 25 | public class CapacitorHttp extends Plugin {
|
26 | 26 |
|
27 |
| - private Map<Runnable, PluginCall> activeRequests = new HashMap<>(); |
| 27 | + private final Map<Runnable, PluginCall> activeRequests = new HashMap<>(); |
28 | 28 | private final ExecutorService executor = Executors.newCachedThreadPool();
|
29 | 29 |
|
30 | 30 | @Override
|
@@ -59,17 +59,26 @@ protected void handleOnDestroy() {
|
59 | 59 | }
|
60 | 60 |
|
61 | 61 | private void http(final PluginCall call, final String httpMethod) {
|
62 |
| - Runnable asyncHttpCall = () -> { |
63 |
| - try { |
64 |
| - JSObject response = HttpRequestHandler.request(call, httpMethod, getBridge()); |
65 |
| - call.resolve(response); |
66 |
| - } catch (Exception e) { |
67 |
| - call.reject(e.getLocalizedMessage(), e.getClass().getSimpleName(), e); |
| 62 | + Runnable asyncHttpCall = new Runnable() { |
| 63 | + @Override |
| 64 | + public void run() { |
| 65 | + try { |
| 66 | + JSObject response = HttpRequestHandler.request(call, httpMethod, getBridge()); |
| 67 | + call.resolve(response); |
| 68 | + } catch (Exception e) { |
| 69 | + call.reject(e.getLocalizedMessage(), e.getClass().getSimpleName(), e); |
| 70 | + } finally { |
| 71 | + activeRequests.remove(this); |
| 72 | + } |
68 | 73 | }
|
69 | 74 | };
|
70 | 75 |
|
71 |
| - activeRequests.put(asyncHttpCall, call); |
72 |
| - executor.submit(asyncHttpCall); |
| 76 | + if (!executor.isShutdown()) { |
| 77 | + activeRequests.put(asyncHttpCall, call); |
| 78 | + executor.submit(asyncHttpCall); |
| 79 | + } else { |
| 80 | + call.reject("Failed to execute request - Http Plugin was shutdown"); |
| 81 | + } |
73 | 82 | }
|
74 | 83 |
|
75 | 84 | @JavascriptInterface
|
|
0 commit comments