« get me outta code hell

Modularize it all - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/promisify-process.js
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-05-31 14:42:22 -0300
committerLiam <towerofnix@gmail.com>2017-05-31 14:42:22 -0300
commit42ec01bb91c517067a9eba901272c1248ed52261 (patch)
treed28bdaa85f9f02028de5f3aad76873a183e0c157 /src/promisify-process.js
parent07626fe82986214d4ef56a5790d864c4bf19b27e (diff)
Modularize it all
Diffstat (limited to 'src/promisify-process.js')
-rw-r--r--src/promisify-process.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/promisify-process.js b/src/promisify-process.js
new file mode 100644
index 0000000..877cb8d
--- /dev/null
+++ b/src/promisify-process.js
@@ -0,0 +1,19 @@
+'use strict'
+
+module.exports = function promisifyProcess(proc, showLogging = true) {
+  return new Promise((resolve, reject) => {
+    if (showLogging) {
+      proc.stdout.pipe(process.stdout)
+      proc.stderr.pipe(process.stderr)
+    }
+
+    proc.on('exit', code => {
+      if (code === 0) {
+        resolve()
+      } else {
+        console.error('Process failed!', proc.spawnargs)
+        reject(code)
+      }
+    })
+  })
+}