Version 1
[yaffs-website] / node_modules / phridge / lib / disposeAll.js
diff --git a/node_modules/phridge/lib/disposeAll.js b/node_modules/phridge/lib/disposeAll.js
new file mode 100644 (file)
index 0000000..30325d0
--- /dev/null
@@ -0,0 +1,26 @@
+"use strict";
+
+var instances = require("./instances.js");
+
+/**
+ * Terminates all running PhantomJS processes. Returns a Promises/A+ compliant promise
+ * which resolves when a processes terminated cleanly.
+ *
+ * @returns {Promise}
+ */
+function disposeAll() {
+    var copy = instances.slice(0); // copy the array because phantom.dispose() will modify it
+
+    return Promise.all(copy.map(exit));
+}
+
+/**
+ * @private
+ * @param {Phantom} phantom
+ * @returns {Promise}
+ */
+function exit(phantom) {
+    return phantom.dispose();
+}
+
+module.exports = disposeAll;