dgram: socket add `asyncDispose` · nodejs/node@c47b2cb · GitHub
Skip to content

Commit c47b2cb

Browse files
atlowChemijuanarbol
authored andcommitted
dgram: socket add asyncDispose
PR-URL: #48717 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 1295c76 commit c47b2cb

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

doc/api/dgram.md

Lines changed: 12 additions & 0 deletions

lib/dgram.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const {
3030
ObjectDefineProperty,
3131
ObjectSetPrototypeOf,
3232
ReflectApply,
33+
SymbolAsyncDispose,
3334
SymbolDispose,
3435
} = primordials;
3536

@@ -59,7 +60,7 @@ const {
5960
validatePort,
6061
} = require('internal/validators');
6162
const { Buffer } = require('buffer');
62-
const { deprecate, guessHandleType } = require('internal/util');
63+
const { deprecate, guessHandleType, promisify } = require('internal/util');
6364
const { isArrayBufferView } = require('internal/util/types');
6465
const EventEmitter = require('events');
6566
const {
@@ -752,6 +753,13 @@ Socket.prototype.close = function(callback) {
752753
return this;
753754
};
754755

756+
Socket.prototype[SymbolAsyncDispose] = async function() {
757+
if (!this[kStateSymbol].handle) {
758+
return;
759+
}
760+
return FunctionPrototypeCall(promisify(this.close), this);
761+
};
762+
755763

756764
function socketCloseNT(self) {
757765
self.emit('close');
Lines changed: 20 additions & 0 deletions

0 commit comments

Comments
 (0)