A brief look at async-await
Presumably the &quot;&#x2F;&#x2F; set state to finished&quot; involves a return statement, otherwise &quot;check()&quot; will continue to be called and ultimately the state will be set back to not done. This applies to both the async version and the chain() version. Personally I find it confusing that the comment hides a control flow statement when the text of the comment suggests that it&#x27;s just setting a state variable.<p>Surely a better comparison for the async function would be a chain() that manually recreates the loop using a parameter or local captured variable, like shown below. They&#x27;re still complex but if anything show the complexity more clearly, especially if 6 is not hardcoded but could be passed as a parameter. I suppose having the unrolled version from the article plus one of these would be best of all, to show the problem from all angles.<p><pre><code>    function chainWithParam() {
        var checkAndIterate;
        checkAndIterate = (result, i) =&gt; {
            if (result) {
                &#x2F;&#x2F; set state to finished
                return;
            }
            if (i == 6) {
                &#x2F;&#x2F; set state to not done
                return;
            }
            check()
                .then(result =&gt; checkAndIterate(result, i + 1))
                .catch(error =&gt; &#x2F;* set state to failed *&#x2F;);
        }
        checkAndIterate(false, 0);
    }
    
    function chainWithCapturedLocal() {
        i = 0;
        var checkAndIterate;
        checkAndIterate = result =&gt; {
            if (result) {
                &#x2F;&#x2F; set state to finished
                return;
            }
            if (i == 6) {
                &#x2F;&#x2F; set state to not done
                return;
            }
            ++i;
            check()
                .then(checkAndIterate)
                .catch(error =&gt; &#x2F;* set state to failed *&#x2F;);
        }
        checkAndIterate(false);
    }
</code></pre>
I&#x27;m not a JavaScript programmer so there could be mistakes in the above code. I&#x27;d be interested to know if there is, especially whether it was really necessary to declare the checkAndIterate variable on a separate line to its assignment.<p>Surely the &quot;manual&quot; function could be implemented with some sort of loop-like