UNPKG

async-try-catch

Version:
1 lines 9.53 kB
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.AsyncTryCatch=e()}})(function(){var e,t,n;return function(){function e(t,n,r){function s(o,c){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(i)return i(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[o]={exports:{}};t[o][0].call(u.exports,function(e){var n=t[o][1][e];return s(n||e)},u,u.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}return e}()({1:[function(e,t,n){(function(n,r){"use strict";function s(){throw new Error("Use AsyncTryCatch.try() instead.")}t.exports=s;s.prototype.__prototypeUID__="async-try-catch/AsyncTryCatch";s.prototype.__prototypeVersion__=e("../package.json").version;if(r.AsyncTryCatch){if(r.AsyncTryCatch.prototype.__prototypeUID__==="async-try-catch/AsyncTryCatch"){var i=s.prototype.__prototypeVersion__.split(".");var o=r.AsyncTryCatch.prototype.__prototypeVersion__.split(".");if(o[0]!==i[0]||i[0]==="0"&&o[1]!==i[1]){throw new Error("Incompatible version of AsyncTryCatch already installed on global.AsyncTryCatch: "+r.AsyncTryCatch.prototype.__prototypeVersion__+", current version: "+s.prototype.__prototypeVersion__)}}else{throw new Error("Incompatible module already installed on global.AsyncTryCatch")}}else{r.AsyncTryCatch=s;r.AsyncTryCatch.stack=[];r.AsyncTryCatch.substituted=false;r.AsyncTryCatch.NextGenEvents=[]}if(n.browser&&!r.setImmediate){r.setImmediate=function e(t){return setTimeout(t,0)};r.clearImmediate=function e(t){return clearTimeout(t)}}if(!r.Vanilla){r.Vanilla={}}if(!r.Vanilla.setTimeout){r.Vanilla.setTimeout=setTimeout}if(!r.Vanilla.setImmediate){r.Vanilla.setImmediate=setImmediate}if(!r.Vanilla.setInterval){r.Vanilla.setInterval=setInterval}if(!r.Vanilla.nextTick){r.Vanilla.nextTick=n.nextTick}s.try=function e(t){var n=Object.create(s.prototype,{fn:{value:t,enumerable:true},parent:{value:r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1]}});return n};s.prototype.catch=function e(t){Object.defineProperties(this,{catchFn:{value:t,enumerable:true}});if(!r.AsyncTryCatch.substituted){s.substitute()}try{r.AsyncTryCatch.stack.push(this);this.fn();r.AsyncTryCatch.stack.pop()}catch(e){r.AsyncTryCatch.stack.pop();this.callCatchFn(e)}};s.prototype.callCatchFn=function e(t){if(!this.parent){this.catchFn(t);return}try{r.AsyncTryCatch.stack.push(this.parent);this.catchFn(t);r.AsyncTryCatch.stack.pop()}catch(e){r.AsyncTryCatch.stack.pop();this.parent.callCatchFn(e)}};s.timerWrapper=function e(t,n,...s){var i,o;if(typeof n!=="function"||!r.AsyncTryCatch.stack.length){return t.call(this,n,...s)}i=r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1];o=function e(...t){var s;try{r.AsyncTryCatch.stack.push(i);s=n(...t);r.AsyncTryCatch.stack.pop();return s}catch(e){r.AsyncTryCatch.stack.pop();i.callCatchFn(e)}};return t.call(this,o,...s)};s.addListenerWrapper=function e(t,n,s,i,o){var c,a,l;if(typeof s==="object"){i=s;s=i.fn;delete i.fn}if(typeof s!=="function"||!r.AsyncTryCatch.stack.length){return t.call(this,n,s,i)}c=r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1];if(o){l=false;a=function e(...t){var i;if(l){return}l=true;this.removeListener(n,a);try{r.AsyncTryCatch.stack.push(c);i=s.call(this,...t);r.AsyncTryCatch.stack.pop();return i}catch(e){r.AsyncTryCatch.stack.pop();c.callCatchFn(e)}}}else{a=function e(...t){var n;try{r.AsyncTryCatch.stack.push(c);n=s.call(this,...t);r.AsyncTryCatch.stack.pop();return n}catch(e){r.AsyncTryCatch.stack.pop();c.callCatchFn(e)}}}a.listener=s;return t.call(this,n,a,i)};s.setTimeout=s.timerWrapper.bind(undefined,r.Vanilla.setTimeout);s.setImmediate=s.timerWrapper.bind(undefined,r.Vanilla.setImmediate);s.setInterval=s.timerWrapper.bind(undefined,r.Vanilla.setInterval);s.nextTick=s.timerWrapper.bind(n,r.Vanilla.nextTick);s.addListener=function e(t,n){return s.addListenerWrapper.call(this,s.NodeEvents.__addListener,t,n)};s.addListenerOnce=function e(t,n){return s.addListenerWrapper.call(this,s.NodeEvents.__addListener,t,n,undefined,true)};s.removeListener=function e(t,n){return s.NodeEvents.__removeListener.call(this,t,n)};s.ngevAddListener=function e(t,n,r){if(n&&typeof n==="object"){if(n.id===undefined){n.id=n.fn}}else if(r&&typeof r==="object"){if(r.id===undefined){r.id=n}}else{r={id:n}}return s.addListenerWrapper.call(this,s.NextGenEvents[this.asyncTryCatchId].on,t,n,r)};s.ngevAddListenerOnce=function e(t,n,r){if(n&&typeof n==="object"){if(n.id===undefined){n.id=n.fn}}else if(r&&typeof r==="object"){if(r.id===undefined){r.id=n}}else{r={id:n}}return s.addListenerWrapper.call(this,s.NextGenEvents[this.asyncTryCatchId].once,t,n,r)};s.ngevRemoveListener=function e(t,n){return s.NextGenEvents[this.asyncTryCatchId].off.call(this,t,n)};s.substitute=function t(){r.AsyncTryCatch.substituted=true;r.setTimeout=s.setTimeout;r.setImmediate=s.setImmediate;r.setInterval=s.setInterval;n.nextTick=s.nextTick;try{s.NodeEvents=r.EventEmitter||e("events")}catch(e){}if(s.NodeEvents){if(!s.NodeEvents.__addListener){s.NodeEvents.__addListener=s.NodeEvents.prototype.on}if(!s.NodeEvents.__addListenerOnce){s.NodeEvents.__addListenerOnce=s.NodeEvents.prototype.once}if(!s.NodeEvents.__removeListener){s.NodeEvents.__removeListener=s.NodeEvents.prototype.removeListener}s.NodeEvents.prototype.on=s.addListener;s.NodeEvents.prototype.addListener=s.addListener;s.NodeEvents.prototype.once=s.addListenerOnce;s.NodeEvents.prototype.removeListener=s.removeListener}for(var i=0;i<s.NextGenEvents.length;i++){s.NextGenEvents[i].prototype.on=s.ngevAddListener;s.NextGenEvents[i].prototype.addListener=s.ngevAddListener;s.NextGenEvents[i].prototype.once=s.ngevAddListenerOnce;s.NextGenEvents[i].prototype.off=s.ngevRemoveListener;s.NextGenEvents[i].prototype.removeListener=s.ngevRemoveListener}};s.restore=function e(){r.AsyncTryCatch.substituted=false;r.setTimeout=r.Vanilla.setTimeout;r.setImmediate=r.Vanilla.setImmediate;r.setInterval=r.Vanilla.setInterval;n.nextTick=r.Vanilla.nextTick;if(s.NodeEvents){s.NodeEvents.prototype.on=s.NodeEvents.__addListener;s.NodeEvents.prototype.addListener=s.NodeEvents.__addListener;s.NodeEvents.prototype.once=s.NodeEvents.__addListenerOnce;s.NodeEvents.prototype.removeListener=s.NodeEvents.__removeListener}for(var t=0;t<s.NextGenEvents.length;t++){s.NextGenEvents[t].prototype.on=s.NextGenEvents[t].on;s.NextGenEvents[t].prototype.addListener=s.NextGenEvents[t].on;s.NextGenEvents[t].prototype.once=s.NextGenEvents[t].once;s.NextGenEvents[t].prototype.off=s.NextGenEvents[t].off;s.NextGenEvents[t].prototype.removeListener=s.NextGenEvents[t].removeListener}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"../package.json":4,_process:3,events:2}],2:[function(e,t,n){},{}],3:[function(e,t,n){var r=t.exports={};var s;var i;function o(){throw new Error("setTimeout has not been defined")}function c(){throw new Error("clearTimeout has not been defined")}(function(){try{if(typeof setTimeout==="function"){s=setTimeout}else{s=o}}catch(e){s=o}try{if(typeof clearTimeout==="function"){i=clearTimeout}else{i=c}}catch(e){i=c}})();function a(e){if(s===setTimeout){return setTimeout(e,0)}if((s===o||!s)&&setTimeout){s=setTimeout;return setTimeout(e,0)}try{return s(e,0)}catch(t){try{return s.call(null,e,0)}catch(t){return s.call(this,e,0)}}}function l(e){if(i===clearTimeout){return clearTimeout(e)}if((i===c||!i)&&clearTimeout){i=clearTimeout;return clearTimeout(e)}try{return i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}var u=[];var d=false;var y;var p=-1;function f(){if(!d||!y){return}d=false;if(y.length){u=y.concat(u)}else{p=-1}if(u.length){h()}}function h(){if(d){return}var e=a(f);d=true;var t=u.length;while(t){y=u;u=[];while(++p<t){if(y){y[p].run()}}p=-1;t=u.length}y=null;d=false;l(e)}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1){for(var n=1;n<arguments.length;n++){t[n-1]=arguments[n]}}u.push(new v(e,t));if(u.length===1&&!d){a(h)}};function v(e,t){this.fun=e;this.array=t}v.prototype.run=function(){this.fun.apply(null,this.array)};r.title="browser";r.browser=true;r.env={};r.argv=[];r.version="";r.versions={};function m(){}r.on=m;r.addListener=m;r.once=m;r.off=m;r.removeListener=m;r.removeAllListeners=m;r.emit=m;r.prependListener=m;r.prependOnceListener=m;r.listeners=function(e){return[]};r.binding=function(e){throw new Error("process.binding is not supported")};r.cwd=function(){return"/"};r.chdir=function(e){throw new Error("process.chdir is not supported")};r.umask=function(){return 0}},{}],4:[function(e,t,n){t.exports={name:"async-try-catch",version:"0.3.6",description:"Async try catch",main:"lib/AsyncTryCatch.js",directories:{test:"test"},dependencies:{},devDependencies:{browserify:"^16.2.2",doormen:"^0.7.20","expect.js":"^0.3.1","nextgen-events":"^0.14.6","uglify-js-es6":"^2.8.9"},scripts:{test:"mocha -R dot"},repository:{type:"git",url:"https://github.com/cronvel/async-try-catch.git"},keywords:["async","try","catch"],author:"Cédric Ronvel",license:"MIT",bugs:{url:"https://github.com/cronvel/async-try-catch/issues"},copyright:{title:"Async Try-Catch",years:[2015,2018],owner:"Cédric Ronvel"}}},{}]},{},[1])(1)});