My main goal is to delay a counter before it triggers.
Imagine a timeout couting down 'n' to '0' and then fire an event, but it can be reset asyncly to 'n' every time something happens.
I tried to achieve this using 'promises' with $q.
I was trying to add dynamicly new promises with timeout inside chaining a brand new delay.
But before achieve this goal, i couldn't even chain new promises.
Example:
var d1 = $q.defer();
var d2 = $q.defer();
d1.promise.then(function(data) {
return 'd1' + data;
});
d2.promise.then(function(data) {
return 'd2' + data;
});
var t = $q.all([d1.promise]);
t.then(function(data) {
console.log(data);
});
$timeout(function()
{
d1.resolve("1000");
}, 1000);
$timeout(function()
{
t.then(function() {
d2.resolve("800");
});
}, 800);
It only outputs: ["1000"] instead of ["1000", "800"]
My search so far:
stackoverflow did not helped me.
angular-promise-tracker I can't understand this code, how it behaves is exactly for what I need. But it is made for something else.