JSFiddle - React, Tailwind, and code Playground

by Gajus Kuizinas

JavaScript

var foo,
    curry,
    controller;
 
foo = function (parameters, callback) {
    setTimeout(function () {
        callback(parameters);
    }, 100);
};
 
curry = function (method) {
    var args = Array.prototype.slice.call(arguments, 1);
 
    return function (callback) {
        args.push(callback);
 
        return method.apply({}, args);
    };
};
 
controller = function (generator) {
    var iterator;
 
    iterator = generator();
 
    function advancer (response) {
        var state;
 
        state = iterator.next(response);
 
        if (!state.done) {
            state.value(advancer);
        }
    }
 
    advancer();
};
 
controller(function * () {
    var a = yield curry(foo, 'a'),
        b = yield curry(foo, 'b'),
        c = yield curry(foo, 'c');
 
    console.log(a, b, c);
});
 
// a b c