nativescript-tasks
NativeScript module for simply invoking and handling background tasks via web workers.
npm i --save nativescript-tasks

npm npm

NativeScript Tasks

A NativeScript module for simply handling background tasks via web workers.

Donate

License

MIT license

Platforms

  • Android
  • iOS

Requirements

Installation

Run

tns plugin add nativescript-tasks

inside your app project to install the module.

Example

import Tasks = require("nativescript-tasks");

Tasks.startNew((ctx) => {
return 23979 + ctx.state;
},
5979) // 5979 will be stored in 'state'
// property of 'ctx'
.then((result) => {
console.log('Result: ' + result.data); // 29958
// result.state = 5979
})
.catch((result) => {
console.log('ERROR: ' + result.error);
// result.state = 5979
});

Limitations

  • You can only submit and return serializable objects and values!
  • All task functions are 'closures', what means that you CANNOT access variables or modules outside such functions. All functions are serialized as strings and submitted to the worker script where "external stuff" is NOT available! The only way to share data with the functions is to submit an optional and serializable "state value".

Read the official documentation to get more information.