Last active
August 29, 2015 13:57
-
-
Save kriskowal/9719411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Connection = require("./q-connection"); | |
var ProcessStream = require("q-io/node/process-stream"); | |
var stream = ProcessStream(process); | |
var remote = Connection(stream, { | |
exit: function (code) { | |
process.exit(code); | |
} | |
}); | |
remote.invoke("greet", "Hello, World!").done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ChildProcess = require("child_process"); | |
var ProcessStream = require("q-io/node/process-stream"); | |
var Connection = require("./q-connection"); | |
var child = ChildProcess.spawn("node", ["child.js"], { | |
stdio: ["ipc"] | |
}); | |
var stream = ProcessStream(child); | |
var remote = Connection(stream, { | |
greet: function (message) { | |
console.log(message); | |
return remote.invoke("exit", 0); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BufferStream = require("../buffer-stream"); | |
module.exports = ProcessStream; | |
function ProcessStream(process) { | |
var input = new BufferStream(); | |
var output = new BufferStream(); | |
var stream = new BufferStream({get: input.get, put: output.put}); | |
process.on("message", function (message) { | |
input.yield(message); | |
}); | |
process.on("close", function () { | |
input.return(0); | |
}); | |
process.on("exit", function (code) { | |
input.return(code); | |
}); | |
output.forEach(function (message) { | |
process.send(message); | |
}); | |
return stream; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ChildProcess = require("child_process"); | |
var ProcessStream = require("q-io/node/process-stream"); | |
var Connection = require("../q-connection"); | |
describe("subprocess exits", function () { | |
it("revokes promise for remote root object", function () { | |
var child = ChildProcess.spawn("true", [], { | |
stdio: ["ipc"] | |
}); | |
var stream = ProcessStream(child); | |
var remote = Connection(stream); | |
return remote.then(function () { | |
expect(false).toBe(true); | |
}, function (error) { | |
expect(error.message).toBe("Can't resolve promise because connection closed"); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment