Issue
I am using NativeScript 2.0 and I am developing an Android module that is NOT allowed to be run in the main thread!
Is there a module that I can use to run a function in a background thread?
Or is it possible to use something like AsyncTask class in "native" JavaScript code (NOT TypeScript!)?
Solution
nativescript added web workers. https://docs.nativescript.org/angular/core-concepts/multithreading-model.html
var worker = new Worker('myWorker');
worker.postMessage('hello');
worker.onmessage = function(msg) {
console.log('answer from worker',msg.data);
}
in worker myWorker.js
require('globals'); // necessary to bootstrap tns modules on the new thread
onmessage = function(msg) {
postMessage('bye');
}
Answered By - Habib Kazemi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.