Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
angrymouse committed Jun 18, 2021
1 parent e6c51e7 commit a3c1666
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
15 changes: 5 additions & 10 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,11 @@ class RFManager {
}
fun(...this.__deserializeArgs(data.args))
.then((res) => {
this.__send(
JSON.stringify({
type: "functionResult",
data: {
reqId: data.reqId,
resultType: "resolve",
result: res,
},
})
);
this.__send("functionResult", {
reqId: data.reqId,
resultType: "resolve",
result: res,
});
})
.catch((error) => {
this.__send(
Expand Down
26 changes: 21 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class RemoteFunctionsServerManager {
clients = [];
__callbacks = new Map();
__awaiting = {};
constructor(functions = []) {
this.functions = new Map(
functions.map((f) => [
Expand Down Expand Up @@ -82,6 +83,16 @@ class RemoteFunctionsServerManager {
client.readyIndicator.resolve();
}
},
functionResult: (data) => {
if (!this.__awaiting[data.reqId]) {
return;
}

this.__awaiting[data.reqId][data.resultType](
data.result
);
delete this.__awaiting[data.reqId];
},
}[message.type](message.data));
} catch (e) {
return client.send(
Expand Down Expand Up @@ -147,11 +158,16 @@ class RemoteFunctionsServerManager {
__callClientFunc(client, fname, args) {
return new Promise((resolve, reject) => {
let reqId = Math.random().toString(16).substr(2);
client.send("callClientFunc", {
fname,
args: this.__serializeArgs(args),
reqId,
});
client.send(
JSON.stringify({
type: "callClientFunc",
data: {
fname,
args: this.__serializeArgs(args),
reqId,
},
})
);
this.__awaiting[reqId] = {
resolve,
reject,
Expand Down

0 comments on commit a3c1666

Please sign in to comment.