nativescript-tasks
NativeScript module for simply invoking and handling background tasks via web workers.
npm i --save nativescript-tasks
- Version: 1.0.8
- GitHub: https://github.com/mkloubert/nativescript-tasks
- NPM: https://npmjs.net.cn/package/nativescript-tasks
- Downloads:
- Last Day: 0
- Last Week: 0
- Last Month: 19
NativeScript Tasks
A NativeScript module for simply handling background tasks via web workers.
License
Platforms
- Android
- iOS
Requirements
- NativeScript 2.4+ (s. Multithreading Model)
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.