From 98bb74d8b1a890a7be9c38c625ccca5a968c0303 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 6 Apr 2023 22:53:15 -0400 Subject: [PATCH] *Change userData logic to throw error if set, but try to always set it --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ac2db1c..bf88bed 100644 --- a/index.js +++ b/index.js @@ -280,7 +280,11 @@ class Channel { module.exports = class Protomux { constructor(stream, { alloc, slave = false } = {}) { - if (stream.userData === null) stream.userData = this; + if (stream.userData) { + throw new Error("Mux already set for this stream"); + } + + stream.userData = this; this.isProtomux = true; this.stream = stream;