Skip to content

Commit

Permalink
refactor: use WeakMap to avoid attaching properties
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Mar 14, 2022
1 parent f293b97 commit 7b98355
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import Deque = require("denque");

const debug = Debug("cluster");

const REJECT_OVERWRITTEN_COMMANDS = new WeakSet<Command>();

type ClusterStatus =
| "end"
| "close"
Expand Down Expand Up @@ -477,11 +479,9 @@ class Cluster extends Commander {
let targetSlot = node ? node.slot : command.getSlot();
const ttl = {};
const _this = this;
// @ts-expect-error
if (!node && !command.__is_reject_overwritten) {
// TODO WeakMap
// @ts-expect-error
command.__is_reject_overwritten = true;
if (!node && !REJECT_OVERWRITTEN_COMMANDS.has(command)) {
REJECT_OVERWRITTEN_COMMANDS.add(command);

const reject = command.reject;
command.reject = function (err) {
const partialTry = tryConnection.bind(null, true);
Expand Down

0 comments on commit 7b98355

Please sign in to comment.