« get me outta code hell

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:
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
+}