JSFiddle - React, Tailwind, and code Playground

by Alexey Ukolov

JavaScript

var isFirstDone = false,
    isSecondDone = false;

function one() {
    console.log('one.start');

    setTimeout(function () {
        console.log('one.done');
        isFirstDone = true;
    }, 2000);

    console.log('one.return');
}

function two() {
    console.log('two.start');

    var interval = setInterval(function () {
        if (isFirstDone) {
            console.log('two.done');
            isSecondDone = true;
            clearInterval(interval);
        }
    }, 100);

    console.log('two.return');
}

function three() {
    console.log('three.start');

    var interval = setInterval(function () {
        if (isSecondDone) {
            console.log('three.done');
            clearInterval(interval);
        }
    }, 100);

    console.log('three.return');
}

one();
two();
three();