async-to-sync
Version:
async-to-sync is help you for Javascript asynchronous function to synchronous function.
1 lines • 1.2 kB
JavaScript
;function _asyncToGenerator(e){return function(){var r=e.apply(this,arguments);return new Promise(function(e,n){function t(a,o){try{var c=r[a](o),u=c.value}catch(e){return void n(e)}if(!c.done)return Promise.resolve(u).then(function(e){t("next",e)},function(e){t("throw",e)});e(u)}return t("next")})}}var ats=function(e,r){var n=function(e){return new Promise(function(r){return e(r)})};_asyncToGenerator(regeneratorRuntime.mark(function t(){var a,o,c,u,i,s;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:t.prev=0,a=!0,o=!1,c=void 0,t.prev=4,u=e[Symbol.iterator]();case 6:if(a=(i=u.next()).done){t.next=13;break}return s=i.value,t.next=10,n(s);case 10:a=!0,t.next=6;break;case 13:t.next=19;break;case 15:t.prev=15,t.t0=t.catch(4),o=!0,c=t.t0;case 19:t.prev=19,t.prev=20,!a&&u.return&&u.return();case 22:if(t.prev=22,!o){t.next=25;break}throw c;case 25:return t.finish(22);case 26:return t.finish(19);case 27:t.next=34;break;case 29:if(t.prev=29,t.t1=t.catch(0),"function"==typeof r){t.next=33;break}return t.abrupt("return",console.error("Error:",t.t1));case 33:r();case 34:case"end":return t.stop()}},t,void 0,[[0,29],[4,15,19,27],[20,,22,26]])}))()};