JSFiddle - React, Tailwind, and code Playground

HTML

<div ng-app="app" ng-controller="MainCtrl">
    <!-- <button ng-click="run()">Run Async</button>
-->
</div>

JavaScript

angular.module('app', []).controller('MainCtrl', function ($scope, $q) {
    function nextStep(n) {
        return step(n + 1);
    }

    function step(n) {
        console.log('step ' + n);
        var deferred = $q.defer();
        (n === 3) ? deferred.reject(n) : deferred.resolve(n);
        return deferred.promise;
    }

    function stepError(n) {
        throw(n);
    }

    function finalError(n) {
        console.log('finalError ' + n);
    }
    step(1)
        .then(nextStep, stepError)
        .then(nextStep, stepError)
        .then(nextStep, stepError)
        .then(nextStep, stepError)
        .then(nextStep, stepError)
        .then(null, finalError);
});