Chaining angular $timeout

angularjs, javascript, promise, timeout

Solution

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); });

Problem

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...

Original source