function Pend(){this.pending=0,this.max=1/0,this.listeners=[],this.waiting=[],this.error=null}function pendHold(n){n.pending+=1;var i=!1;return function(t){if(i)throw new Error("callback called twice");if(i=!0,n.error=n.error||t,n.pending-=1,n.waiting.length>0&&n.pending<n.max)pendGo(n,n.waiting.shift());else if(0===n.pending){var r=n.listeners;n.listeners=[],r.forEach(e)}};function e(i){i(n.error)}}function pendGo(n,i){i(pendHold(n))}module.exports=Pend,Pend.prototype.go=function(n){this.pending<this.max?pendGo(this,n):this.waiting.push(n)},Pend.prototype.wait=function(n){0===this.pending?n(this.error):this.listeners.push(n)},Pend.prototype.hold=function(){return pendHold(this)};