Sha256: e429a7f0de6ec08748c4286dc548de51cae77a2cfdfaeaf0f3938fbc3a01eb5d

Contents?: true

Size: 1.44 KB

Versions: 34

Compression:

Stored size: 1.44 KB

Contents

'use strict';

var Functor = require('./functor'),
    Pledge  = require('./pledge');

var Cell = function(tuple) {
  this._ext     = tuple[0];
  this._session = tuple[1];

  this._functors = {
    incoming: new Functor(this._session, 'processIncomingMessage'),
    outgoing: new Functor(this._session, 'processOutgoingMessage')
  };
};

Cell.prototype.pending = function(direction) {
  var functor = this._functors[direction];
  if (!functor._stopped) functor.pending += 1;
};

Cell.prototype.incoming = function(error, message, callback, context) {
  this._exec('incoming', error, message, callback, context);
};

Cell.prototype.outgoing = function(error, message, callback, context) {
  this._exec('outgoing', error, message, callback, context);
};

Cell.prototype.close = function() {
  this._closed = this._closed || new Pledge();
  this._doClose();
  return this._closed;
};

Cell.prototype._exec = function(direction, error, message, callback, context) {
  this._functors[direction].call(error, message, function(err, msg) {
    if (err) err.message = this._ext.name + ': ' + err.message;
    callback.call(context, err, msg);
    this._doClose();
  }, this);
};

Cell.prototype._doClose = function() {
  var fin  = this._functors.incoming,
      fout = this._functors.outgoing;

  if (!this._closed || fin.pending + fout.pending !== 0) return;
  if (this._session) this._session.close();
  this._session = null;
  this._closed.done();
};

module.exports = Cell;

Version data entries

34 entries across 33 versions & 12 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.18.0 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.18.2 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.16.1 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.15.2 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.18.4 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.18.1 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.14.0 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
tang-0.2.1 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/cell.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/websocket-extensions/lib/pipeline/cell.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/websocket-extensions/lib/pipeline/cell.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/websocket-extensions/lib/pipeline/cell.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/websocket-extensions/lib/pipeline/cell.js
tang-0.2.0 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/cell.js
tang-0.1.0 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/cell.js
tang-0.0.9 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/cell.js
enju_library-0.3.8 spec/dummy/node_modules/websocket-extensions/lib/pipeline/cell.js
ilog-0.4.1 node_modules/websocket-extensions/lib/pipeline/cell.js