summaryrefslogtreecommitdiff
path: root/lib/dgram.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dgram.js')
-rw-r--r--lib/dgram.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index 35d414320a..94f44d5202 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -211,8 +211,21 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
state.bindState = BIND_STATE_BINDING;
- if (arguments.length && typeof arguments[arguments.length - 1] === 'function')
- this.once('listening', arguments[arguments.length - 1]);
+ const cb = arguments.length && arguments[arguments.length - 1];
+ if (typeof cb === 'function') {
+ function removeListeners() {
+ this.removeListener('error', removeListeners);
+ this.removeListener('listening', onListening);
+ }
+
+ function onListening() {
+ removeListeners.call(this);
+ cb.call(this);
+ }
+
+ this.on('error', removeListeners);
+ this.on('listening', onListening);
+ }
if (port instanceof UDP) {
replaceHandle(this, port);