Skip to content
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

dgram: return self on .bind() and .close() #214

Closed

Conversation

brendanashworth
Copy link
Contributor

These commits add two functionalities to the lib/dgram.js library: a datagram Socket should return itself when it is both closed and bound to a host.

This can be used for better chaining of functions, i.e.:

var socket = dgram.createSocket('udp4').bind(1234);

I ran across this when I was working with the datagram module and chained it like above ^, expecting it to behave like the net module does. These two commits basically make it function like the net module now.

> var net = require('net'); var dgram = require('dgram');
undefined
> var server = net.createServer(function() {});
undefined
> var socket = dgram.createSocket('udp4');
undefined
> server.listen(8124) == server;
true
> socket.bind(8124) == socket;
false

I also added tests, I hope those tests are satisfactory, and should this be merged into io.js I'll send a PR into node.js.

@bnoordhuis
Copy link
Member

LGTM but can you make the commit log conform to the convention? See CONTRIBUTING.md or git log lib/dgram.js for examples.

This commit changes `lib/dgram.js` Sockets to, when
they are bound to a port / IP, return themselves. This
is done in order to allow chaining of methods and be
in accordance with the `lib/net.js` library.
This commit adds a return statement to the dgram.Socket.close()
function that returns itself after it finishes. This follows along
the functionality of the more popular and, dare I say, father-library
`lib/net.js`.
@brendanashworth
Copy link
Contributor Author

@bnoordhuis I think its fixed!

bnoordhuis pushed a commit to bnoordhuis/io.js that referenced this pull request Dec 30, 2014
This commit changes `lib/dgram.js` Sockets to, when
they are bound to a port / IP, return themselves. This
is done in order to allow chaining of methods and be
in accordance with the `lib/net.js` library.

PR-URL: nodejs#214
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
bnoordhuis pushed a commit to bnoordhuis/io.js that referenced this pull request Dec 30, 2014
This commit adds a return statement to the dgram.Socket.close()
function that returns itself after it finishes. This follows along
the functionality of the more popular and, dare I say, father-library
`lib/net.js`.

PR-URL: nodejs#214
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@bnoordhuis
Copy link
Member

Thanks Brendan, landed in 3e0057d and 4444b7b!

@bnoordhuis bnoordhuis closed this Dec 30, 2014
@brendanashworth brendanashworth deleted the dgram-return-self branch March 8, 2015 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants