"use strict";var Cell=require("./cell"),Pledge=require("./pledge"),Pipeline=function(e){this._cells=e.map(function(e){return new Cell(e)}),this._stopped={incoming:!1,outgoing:!1}};Pipeline.prototype.processIncomingMessage=function(e,i,n){this._stopped.incoming||this._loop("incoming",this._cells.length-1,-1,-1,e,i,n)},Pipeline.prototype.processOutgoingMessage=function(e,i,n){this._stopped.outgoing||this._loop("outgoing",0,this._cells.length,1,e,i,n)},Pipeline.prototype.close=function(e,i){this._stopped={incoming:!0,outgoing:!0};var n=this._cells.map(function(e){return e.close()});e&&Pledge.all(n).then(function(){e.call(i)})},Pipeline.prototype._loop=function(e,i,n,o,t,l,s){for(var p=this._cells,c=p.length,g=this;c--;)p[c].pending(e);var r=function(i,t,c){if(i===n)return l.call(s,t,c);p[i][e](t,c,function(n,t){n&&(g._stopped[e]=!0),r(i+o,n,t)})};r(i,null,t)},module.exports=Pipeline;