-
Notifications
You must be signed in to change notification settings - Fork 10
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
callback for listen ? #5
Comments
Callback might be hard to support for node, because it has server.onerror = err => console.log('some server error');
server.onlistening = () => console.log('listening'); |
I'd prefer extending an EventEmitter for Server instead of onerror, onlistening, anyhow it needs to be aware of the listen callback from the backend. I was hoping something like this function listen(handle, port, callback){
handle.listen(port);
handle.once('listen', callback);
} or even better with promises // proimisified by bluebird.
function listen(handle, port, callback){
return handle.listenAsync(port);
} As mentioned here https://nodejs.org/api/net.html#net_server_listen_path_backlog_callback
Then with the power of ES 7 async/await we can simply just make them completely async calls. Even without ES7 the promise way in general will make your server code much cleaner :-) and we can pipe promises. |
This lib doesn't use EventEmitter, so events are handled by properties like something like this for Node: function listen(handle, port, cb) {
handle.listen(port, function() {
server.onlistening();
cb();
});
} |
I am forking the lib, to add event emitter which are supported natively in node and mostly in browsers and visionmedia/debug support expect PR 👍 :-) |
I'd keep it without event emitter, it's a little faster and it's one less dependency. |
After looking at runtimejs.org I understand why you wish to keep this extremely low dependency. |
@darkyen I have no idea what you’re talking about, runtimejs.org is filled with dependencies everywhere. You even have files that require each other in the project. If you want to have the event emitter why not use express server? It’s got everything you need. This is a very nice http library because it’s so adaptable. If you could make it parameter passed library I don’t see a problem with that, but don’t make it require it out of the box, it removes it’s portability. |
Listen might throw error, and can be fairly non-sync. I don't think there is error mechanism in the library so far, callback for listen maybe ?
The text was updated successfully, but these errors were encountered: