I'm trying to chain calls to AngularJS's $timeout
function. I've seen lots of threads on here which allow the chaining of promises, some specifically using angular's $q
, but this seems like it should be super simple. I guess I'm missing something obvious. Here's what I'd like to do:
$timeout(firstFunction, firstDelay)
.then($timeout(secondFunction, secondDelay))
.then($timeout(thirdFunction, thirdDelay));
While all three functions get called, the $timeout
s all start simultaneously. I can see why this doesn't work, but how do I get what I want? Can I even use promises here? I was previously just arranging the delays so that they cascade, but that seems like more work to maintain...
The $timeout
s are executing immediately. Wrap them in functions that will be called when each promise resolves...
$timeout(firstFunction, firstDelay)
.then(function () { return $timeout(secondFunction, secondDelay); })
.then(function () { return $timeout(thirdFunction, thirdDelay); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With