mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
# Conflicts: # jsowell-ui/.env.development # jsowell-ui/.env.staging # jsowell-ui/bin/build-sit.bat # jsowell-ui/bin/build.bat # jsowell-ui/src/api/adapayMember/adapayMember.js # jsowell-ui/src/api/pile/merchant.js # jsowell-ui/src/router/index.js # jsowell-ui/src/views/financial/financeDetail.vue # jsowell-ui/src/views/financial/merchant.vue # jsowell-ui/src/views/homeIndex/homeIndex.vue # jsowell-ui/src/views/login.vue # jsowell-ui/src/views/pile/basic/detail.vue # jsowell-ui/src/views/pile/station/components/SiteInfo.vue # jsowell-ui/src/views/pile/station/detail.vue # jsowell-ui/src/views/pile/station/orderReport.vue
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
'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;
|