Is this possible to trigger a method every 10 minutes in typescript/angular2?
And second question, is this possible to call a method everytime local time reaches multiply of 10 minutes? Like:
5:00 then 5:10 then 5:20 then 5:30 then 5:40...
You can do that using Reactive-Extensions/RxJS.
Rx.Observable.timer(dueTime, [period], [scheduler])
Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
This is just an example from the doc.Hope you can use it easily with your use case.
var source = Rx.Observable.timer(200, 100)
.timeInterval()
.pluck('interval')
.take(3);
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 200
// => Next: 100
// => Next: 100
// => Completed