Skip to content

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

Closed
brendanashworth wants to merge 2 commits into
nodejs:v0.12from
brendanashworth:dgram-return-self
Closed

dgram: return self on .bind() and .close()#214
brendanashworth wants to merge 2 commits into
nodejs:v0.12from
brendanashworth:dgram-return-self

Conversation

@brendanashworth

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

2 participants