Add a simple worker thread to validate worker-thread setup

This commit is contained in:
James Babcock committed 2026-07-06 14:45:28 -07:00
1 parent 1533c550b4
commit c83448873e
3 files changed
+60

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
/**
* Trivial echo worker: spike scaffolding for the app-shell architecture.
* Validates that worker chunks build under @nativescript/webpack, that
* message passing works in both directions, and that a worker isolate can
* call Java APIs directly.
*/
import "@nativescript/core/globals";
declare const global: any;
declare const java: any;
global.onmessage = (event: { data: any }) => {
// Direct Java call from the worker isolate: this runs on the worker's own
// JVM-attached thread, not the main thread.
const javaThreadName = String(java.lang.Thread.currentThread().getName());
global.postMessage({
type: "pong",
echoed: event.data,
workerJavaThreadName: javaThreadName,
workerReceivedAtMs: Date.now(),
});
};