JSFiddle - React, Tailwind, and code Playground
JavaScript
function _get(callback) {
setTimeout(function () {
//callback.call(null);
callback.call(null, new Error('Exception catched'));
}, 1000);
}
function sync(generator) {
var iterator, resume;
resume = function (error, result) {
if (error) {
iterator.throw(error);
}
iterator.next(result);
};
iterator = generator(resume);
iterator.next();
}
sync(function* (resume) {
try {
var x = yield _get(resume);
document.body.innerHTML += 'Everything is ok';
} catch (e) {
document.body.innerHTML += (e.message + '<br>');
}
});