go-style-error
Version:
A utility library for elegant async/await error handling inspired by Go's error handling pattern
2 lines (1 loc) • 731 B
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});var s=(t,o,r)=>new Promise((n,a)=>{var i=e=>{try{c(r.next(e))}catch(u){a(u)}},l=e=>{try{c(r.throw(e))}catch(u){a(u)}},c=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,l);c((r=r.apply(t,o)).next())});function p(t,o){return s(this,null,function*(){try{return[null,yield t()]}catch(r){return[r instanceof Error?r:new Error(String(r)),o]}})}function T(t,o){return s(this,null,function*(){try{return[null,yield t]}catch(r){return[r instanceof Error?r:new Error(String(r)),o]}})}function E(t,o){try{return[null,t()]}catch(r){return[r instanceof Error?r:new Error(String(r)),o]}}exports.default = p; exports.to = p; exports.toPromise = T; exports.toSync = E;