-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add listening/close events, and a close() function #56
Conversation
…and apparently the PR needs fixing for node 0.6 and 0.4… brb |
Thanks @timoxley for the pull request (and updating the tests to pass). I'll have time tomorrow to review this (and the other pending pull requests) and comment/merge. |
I agree that Option 3 would be best, but enforcing What about a combination of Option 2 and Option 3? We could change Thoughts? |
The hybrid concept sounds reasonable. Agree, major breaking changes should definitely go in a 2.x. |
The underlying problem though, probably, is (mis)using events to drive the procedure calls, which removes the ability to use events for any asynchronous things that can happen with a http connection, plus it's also a little strange IMO. Ideally, the remote interface would simply be an object representing the available API, and it uses something like the following to actually invoke the api: //pseudo code
remote.on('methodCall', function(method, args) {
server[method].apply(server, args);
}); Now I think about it, this is exactly how I abstracted your api in my own app though this is really a discussion for post 1.x. |
One other option would be to provide an optional 'on listening' callback to the constructor |
or a .ready function that would be called when the server is ready |
First, sorry for my delayed responses. I'm in the process of moving to San Francisco and that's taking up most of my time. I added an issue to discuss the 'methodCall' event. While we both agree it probably belongs in a 2.x, I didn't want to forget about it. And this way others can discuss later if they want to. I think the move could be good, but I do admit I like the convenience of Is the reason for adding a I'll be happy to implement the hybrid approach + listener in constructor (or a .ready) if you'd like, but a heads up that it may be after the move. |
Gah, sorry for the delay, I went on holiday. :D The reason for .ready/constructor is exactly that. A I'll put the listener in the constructor, I think that's the most concise of the options. PR incoming. |
Add listening/close events, and a close() function
Irritating using xmlrpc in a test suite as there's no easy way to stop the server from listening on a port. This patch forwards the http server's 'listening' and 'close' events, and exposes a close() function on the server.
This would allow your own server tests to not require use of unreliable stuff like
setTimeout(doStuff, 500)
to "ensure" server is listening.One tricky issue that needs to be resolved though, is the fact that normal rpc calls are named events, and this could create confusion for anyone who happens to want to call functions named 'close' or 'listening'.
Three possible solutions:
Last solution probably the best but also most disruptive, second solution good middle ground but verbose, first solution easiest, but doesn't fully solve the problem. Let me know which option sounds good to you and it will be done.