await-to-done
Version:
Async await wrapper for easy error handling
8 lines (7 loc) • 1.09 kB
JavaScript
/*!
* await-to-done v1.1.1
* Async await wrapper for easy error handling
* (c) 2021-2024 saqqdy
* Released under the MIT License.
*/
this.awaitToDone=function(){"use strict";return"function"==typeof SuppressedError&&SuppressedError,function(r){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return Array.isArray(r)?Promise.all(r).then((function(r){return[null,r]})).catch((function(r){return[r,void 0]})):0===n.length?r.then((function(r){return[null,r]})).catch((function(r){return[r,void 0]})):Promise.all(function(r,n,t){if(t||2===arguments.length)for(var e,o=0,u=n.length;o<u;o++)!e&&o in n||(e||(e=Array.prototype.slice.call(n,0,o)),e[o]=n[o]);return r.concat(e||Array.prototype.slice.call(n))}([r],function(r,n){var t="function"==typeof Symbol&&r[Symbol.iterator];if(!t)return r;var e,o,u=t.call(r),i=[];try{for(;(void 0===n||n-- >0)&&!(e=u.next()).done;)i.push(e.value)}catch(r){o={error:r}}finally{try{e&&!e.done&&(t=u.return)&&t.call(u)}finally{if(o)throw o.error}}return i}(n),!1)).then((function(r){return[null,r]})).catch((function(r){return[r,void 0]}))}}();