« get me outta code hell

support queue controls over socket clients - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/general-util.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-07-11 16:22:01 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 18:55:01 -0300
commit2c7e3c8fb279f20da3d1b4f5610e65dc43a22ac2 (patch)
tree39a3aee1c9611141ac38487e06659002e57c124b /general-util.js
parente6698a135099348b62d295e904580f4341447958 (diff)
support queue controls over socket clients
Diffstat (limited to 'general-util.js')
-rw-r--r--general-util.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/general-util.js b/general-util.js
index b767a1b..b4491de 100644
--- a/general-util.js
+++ b/general-util.js
@@ -335,3 +335,17 @@ export async function parseOptions(options, optionDescriptorMap) {
 }
 
 parseOptions.handleDashless = Symbol()
+
+export function silenceEvents(emitter, eventsToSilence, callback) {
+  const oldEmit = emitter.emit
+
+  emitter.emit = function(event, ...data) {
+    if (!eventsToSilence.includes(event)) {
+      oldEmit.apply(emitter, [event, ...data])
+    }
+  }
+
+  callback()
+
+  emitter.emit = oldEmit
+}