Skip to content

Commit bf1924a

Browse files
committed
Move receive operation to background thread
1 parent e337188 commit bf1924a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

android/app/src/main/java/betaflight/configurator/plugin/SocketPlugin.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@ public void receive(PluginCall call) {
104104
call.reject("Not connected to any server");
105105
return;
106106
}
107-
try {
108-
String data = reader.readLine();
109-
JSObject ret = new JSObject();
110-
ret.put("data", data);
111-
call.resolve(ret);
112-
} catch (Exception e) {
113-
call.reject("Receive failed: " + e.getMessage());
114-
}
107+
108+
// Run read operation on a background thread to avoid blocking the UI
109+
getBridge().getExecutor().execute(() -> {
110+
try {
111+
String data = reader.readLine();
112+
JSObject ret = new JSObject();
113+
ret.put("data", data);
114+
call.resolve(ret);
115+
} catch (Exception e) {
116+
call.reject("Receive failed: " + e.getMessage());
117+
}
118+
});
115119
}
116120

117121
@PluginMethod

0 commit comments

Comments
 (0)