diff --git a/lib/index.js b/lib/index.js index 30dc184b9e41c1333360e814085ba006e17d670e..511bf6789c2af48fcda886f07231e7b7455aa38e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,11 +1,15 @@ -//const path = require("path"); - "use strict"; +var path = require("path"); +var worker = require(path.join(__dirname, "worker.js")); + function factory(arg) { - var fn = typeof arg === "function"; + var fn = typeof arg === "function", + obj = undefined; + + obj = worker(arg, fn); - return fn; + return obj; } module.exports = factory; diff --git a/lib/worker.js b/lib/worker.js new file mode 100644 index 0000000000000000000000000000000000000000..35e0866ef95f581dc6e38100d7e3f3f3744d72f8 --- /dev/null +++ b/lib/worker.js @@ -0,0 +1,15 @@ +"use strict"; + +var spawn = require("child_process").spawn; + +function factory(arg) { + var ps = spawn("grep", [arg]); + + ps.on("close", function (code, signal) { + console.log("child process terminated due to receipt of signal " + signal); + }); + + return ps; +} + +module.exports = factory; diff --git a/src/index.js b/src/index.js index 7c9cf2af9b4109f0cf58d80f00aa32a73df14744..b884591dcc349900b4ad1c3a25a05c7a35c6db31 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,13 @@ -//const path = require("path"); +const path = require("path"); +const worker = require(path.join(__dirname, "worker.js")); function factory (arg) { - let fn = typeof arg === "function"; + let fn = typeof arg === "function", + obj; - return fn; + obj = worker(arg, fn); + + return obj; } module.exports = factory; diff --git a/src/worker.js b/src/worker.js new file mode 100644 index 0000000000000000000000000000000000000000..c123c888b9805ee8d4a4ccd94d4f164ab54d03ba --- /dev/null +++ b/src/worker.js @@ -0,0 +1,13 @@ +const spawn = require("child_process").spawn; + +function factory (arg) { + let ps = spawn("grep", [arg]); + + ps.on("close", function (code, signal) { + console.log("child process terminated due to receipt of signal " + signal); + }); + + return ps; +} + +module.exports = factory;