JSFiddle - React, Tailwind, and code Playground

by Gajus Kuizinas

JavaScript

/**
 * Initiates a generator and iterates through each function supplied
 * via the yield operator.
 * 
 * @param {Function}
 */
var controller = function (generator) {
    var iterator;
 
    iterator = generator();
 
    function advancer (response) {
        var state;
 
        // Advance the iterator using the response of an asynchronous callback.
        state = iterator.next(response);
 
        if (!state.done) {
            // Make the asynchronous function call the advancer.
            state.value(advancer);
        }
    }
 
    advancer();
};