Skip to content

Commit

Permalink
Merge pull request #122 from jayantk/delete
Browse files Browse the repository at this point in the history
Use delete to avoid memory leak
  • Loading branch information
mkozjak authored Oct 25, 2021
2 parents 352789c + 6332dc7 commit d5c34c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build-ts/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class CommonClient extends EventEmitter {
this.queue[rpc_id] = { promise: [resolve, reject] };
if (timeout) {
this.queue[rpc_id].timeout = setTimeout(() => {
this.queue[rpc_id] = null;
delete this.queue[rpc_id];
reject(new Error("reply timeout"));
}, timeout);
}
Expand Down Expand Up @@ -235,7 +235,7 @@ export default class CommonClient extends EventEmitter {
this.queue[message.id].promise[1](message.error);
else
this.queue[message.id].promise[0](message.result);
this.queue[message.id] = null;
delete this.queue[message.id];
});
this.socket.addEventListener("error", (error) => this.emit("error", error));
this.socket.addEventListener("close", ({ code, reason }) => {
Expand Down
4 changes: 2 additions & 2 deletions dist/index.browser-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var CommonClient = /*#__PURE__*/function (_EventEmitter) {

if (timeout) {
_this2.queue[rpc_id].timeout = setTimeout(function () {
_this2.queue[rpc_id] = null;
delete _this2.queue[rpc_id];
reject(new Error("reply timeout"));
}, timeout);
}
Expand Down Expand Up @@ -514,7 +514,7 @@ var CommonClient = /*#__PURE__*/function (_EventEmitter) {
if ("error" in message === "result" in message) _this4.queue[message.id].promise[1](new Error("Server response malformed. Response must include either \"result\"" + " or \"error\", but not both."));
if (_this4.queue[message.id].timeout) clearTimeout(_this4.queue[message.id].timeout);
if (message.error) _this4.queue[message.id].promise[1](message.error);else _this4.queue[message.id].promise[0](message.result);
_this4.queue[message.id] = null;
delete _this4.queue[message.id];
});
this.socket.addEventListener("error", function (error) {
return _this4.emit("error", error);
Expand Down
4 changes: 2 additions & 2 deletions dist/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ var CommonClient = /*#__PURE__*/function (_EventEmitter) {

if (timeout) {
_this2.queue[rpc_id].timeout = setTimeout(function () {
_this2.queue[rpc_id] = null;
delete _this2.queue[rpc_id];
reject(new Error("reply timeout"));
}, timeout);
}
Expand Down Expand Up @@ -454,7 +454,7 @@ var CommonClient = /*#__PURE__*/function (_EventEmitter) {
if ("error" in message === "result" in message) _this4.queue[message.id].promise[1](new Error("Server response malformed. Response must include either \"result\"" + " or \"error\", but not both."));
if (_this4.queue[message.id].timeout) clearTimeout(_this4.queue[message.id].timeout);
if (message.error) _this4.queue[message.id].promise[1](message.error);else _this4.queue[message.id].promise[0](message.result);
_this4.queue[message.id] = null;
delete _this4.queue[message.id];
});
this.socket.addEventListener("error", function (error) {
return _this4.emit("error", error);
Expand Down
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class CommonClient extends EventEmitter
{
this.queue[rpc_id].timeout = setTimeout(() =>
{
this.queue[rpc_id] = null
delete this.queue[rpc_id]
reject(new Error("reply timeout"))
}, timeout)
}
Expand Down Expand Up @@ -363,7 +363,7 @@ export default class CommonClient extends EventEmitter
else
this.queue[message.id].promise[0](message.result)

this.queue[message.id] = null
delete this.queue[message.id]
})

this.socket.addEventListener("error", (error) => this.emit("error", error))
Expand Down

0 comments on commit d5c34c7

Please sign in to comment.