Similar to javascript's setTimeout but works well when iPhone/Android goes to sleep on background !
Install dependencies with npm:
npm i mustafah/background-timerimport BackgroundTimer from 'background-timer';new BackgroundTimer(60 * 1000,
() => console.log(`You were waiting this from a minute ago 👍`);
).start();@partial export class EmployeeWork {
@partial model: EmployeeModel;
doWork() {
console.log(`doWork()`);
}
}new BackgroundTimer(60 * 1000, {
tickCallback: (remaining) => {
console.log(`Remaining time = ${remaining}`);
// Every second this function will be called until time is finished
// Will output:
// Remaining time = 01:00
// Remaining time = 00:59
// ...
},
finishCallback: () => {
console.log(`Finshed 👍`);
}
}).start();new BackgroundTimer(60 * 1000, {
tickInterval: 1000 * 2,
tickCallback: (remaining, remaingingMS) => {
console.log(`Remaining time = ${remainingMS}`);
// Tthis function will be called every two seconds !
// Remaining time = 60000
// Remaining time = 58000
// Remaining time = 56000
// ...
},
finishCallback: () => {
console.log(`Finshed 👍`);
},
}).start();