We are building an app which we are using a cordova plugin that runs heavy duty job. The app is being built using Ionic 3. Currently, we are using the current single thread mechanism. Now we think to move in multi-threading and obviously Web Worker. Assume the code looks like:
@Component(…)
export class BasketComponent {
async doHeavyJob() {
await this.heavyJobService.firstStepOfHeavyJob();
await this.heavyJobService.secondStepOfHeavyJob();
}
}
and the heavy service looks like:
import { PrintTable } from “./printTable”;
import { Pro } from “@ionic/pro”;
import { ErrorLoggingService } from “…/…/services/ErrorLoggingService”;
export class HeavyJobService {
heavyCordovaPlugin: any;
constructor() {
this.heavyCordovaPlugin = (<any>window).heavyCordovaPlugin;
}
firstStepOfHeavyJob() {
this.heavyCordovaPlugin.firstStepOfHeavyJob()
}
secondStepOfHeavyJob() {
this.heavyCordovaPlugin.firstStepOfHeavyJob()
}
}
and firstStepOfHeavyJob will call Cordova plugin which looks like:
var exec = require(‘cordova/exec’);
var PLUGIN_NAME = ‘posprinter’;
var posprinter = {
firstStepOfHeavyJob: function () {
return new Promise(function (successCallback, errorCallback) {
exec(successCallback, errorCallback, PLUGIN_NAME, ‘firstStepOfHeavyJob’, []);
});
},
secondStepOfHeavyJob: function () {
return new Promise(function (successCallback, errorCallback) {
exec(successCallback, errorCallback, PLUGIN_NAME, ‘secondStepOfHeavyJob’, []);
});
},
};
module.exports = heavyCordovaPlugin;
Now my question is how I can fit Web Worker into our solution?