"use strict";var Functor=require("./functor"),Pledge=require("./pledge"),Cell=function(e){this._ext=e[0],this._session=e[1],this._functors={incoming:new Functor(this._session,"processIncomingMessage"),outgoing:new Functor(this._session,"processOutgoingMessage")}};Cell.prototype.pending=function(e){var s=this._functors[e];s._stopped||(s.pending+=1)},Cell.prototype.incoming=function(e,s,o,t){this._exec("incoming",e,s,o,t)},Cell.prototype.outgoing=function(e,s,o,t){this._exec("outgoing",e,s,o,t)},Cell.prototype.close=function(){return this._closed=this._closed||new Pledge,this._doClose(),this._closed},Cell.prototype._exec=function(e,s,o,t,n){this._functors[e].call(s,o,function(e,s){e&&(e.message=this._ext.name+": "+e.message),t.call(n,e,s),this._doClose()},this)},Cell.prototype._doClose=function(){var e=this._functors.incoming,s=this._functors.outgoing;this._closed&&e.pending+s.pending===0&&(this._session&&this._session.close(),this._session=null,this._closed.done())},module.exports=Cell;