Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed Dec 6, 2021
1 parent 04ff0d7 commit 707998b
Showing 1 changed file with 0 additions and 112 deletions.
112 changes: 0 additions & 112 deletions lib/bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,116 +176,4 @@ const Bridge = ({
};
};

class B {
constructor({
config: {
request = {
waitTime: 30000
},
id: bridgeId
} = {}
} = {}) {
this.config = {
request
};
this.method = Methods();
this.nodeId = Symbol(bridgeId || ++id);
this.request = Waiters({
nodeId: this.nodeId,
config: this.config.request
});
}

intersect({other}) {
this.other = other;
}

async redirect({direction, packet, request} = {}) {
if (direction === 'in') {
(async() => {
try {
const {meta: {idx, nodeId, ...meta}} = packet;
const {match} = request;
if (match && match.idx && match.nodeId) {
meta.idx = match.idx;
meta.nodeId = match.nodeId;
}
const o1 = await this.other?.pass?.({
direction: directions.reversed[direction],
packet: {
...packet,
meta,
match: packet.meta
}
});
o1 && await o1?.promise;
} catch (e) {
console.error(e);
}
})();
}
return request;
}

async pass({direction, packet: {...packet}}) {
const {match} = packet;
const requestFound = this.request.find(packet);
packet = fillMeta(requestFound, packet);
const methodCallResult = await callMethod({
methods: this.method,
context: {nodeId: this.nodeId}
})({
direction,
packet
});
// @TODO do something when method not found
const packetNew = {
...packet,
...methodCallResult,
match: undefined
};
if (!requestFound) {
const request = this.request.add({
packet: packetNew,
match,
onLocalReject: (errorFullPacket) => {
return this.pass({
direction: directions.reversed[direction],
packet: {
...packetNew,
...errorFullPacket
}
})
}
});
return this.redirect({
direction,
request,
packet: {
...packetNew,
meta: packetNew.meta && {
...packetNew.meta,
idx: request.idx,
nodeId: request.nodeId
}
}
});
}
this.request.fulfill(requestFound)(packetNew);
return this.redirect({
direction,
packet: packetNew,
request: requestFound,
match
});
}

async destroy() {
if (this.request) {
this.request.destroy();
this.request = null;
}
}
}

module.exports = Bridge;

0 comments on commit 707998b

Please sign in to comment.