0

I am new in nativescript in general and I am trying to understand how nativescript-bluetooth LE plugin works.

In particular, I would understand if the function defined on "onDiscovered" will be executed in the main thread or in a separate thread. I read that in general Bluetooth LE it is all executed in a separated thread but I am still much confusion.

bluetooth.startScanning({
  serviceUUIDs: [],
  seconds: 4,
  onDiscovered: function (peripheral) {
    console.log("Periperhal found with UUID: " + peripheral.UUID);
  }
}).then(function() {
  console.log("scanning complete");
}, function (err) {
  console.log("error while scanning: " + err);
});

Can somebody help me to clarify this point?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
zed87
  • 435
  • 5
  • 16

1 Answers1

0

In NativeScript the JavaScript is executed in the main thread (a.k.a. UI Thread). However, you can create background tasks - see details here on how to create workers (which will run on a background thread) or use this sample application as a reference on how to create a background service (suitable for long-running tasks that needs to be handled when your application is off or in the background)

Nick Iliev
  • 9,610
  • 3
  • 35
  • 89
  • I know workers but nativescript-bluetooth plugin does not run scan into the worker. still i dont understand if this is due to an issue with the plugin or with the worker. https://github.com/EddyVerbruggen/nativescript-bluetooth/issues/80. For this reason i am interested to understand if bluetooth startscanning method exec the code into another thread. – zed87 Jul 18 '18 at 09:26