const delay = ms => new Promise(ok => setTimeout(() => ok(ms), ms)) function* likeAsync() { console.log(1) console.log(yield 1.5) let res1 = yield delay(2000) console.log(2, res1) let res2 = yield delay(2000) console.log(3, res2) try { console.log(yield fetch("htpsdasd://localhost:10000")) } catch (e) { console.log('GENA ERROR CATCH', e) } let res3 = yield delay(3000) console.log(4, res3) } let likeA = likeAsync() console.log(likeA.next()) console.log(likeA.next().value.then(res => console.log(res))) function run(gena) { let iter = gena() function next(res, err) { let value, done try { if(!err) { //литеральная деструктуризация??? [{value, done}] = [iter.next(res)] } else { [{value, done}] = [iter.throw(err)] } if (done) return; if(value && typeof value?.then === 'function') { value.then(next, err => next(undefined, err)) } else if (value){ next(value) } } catch(e) { console.warn('gena error', e) } } next() }