-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: support AbortSignal in createSocket
- Loading branch information
Nitzan Uziely
committed
Jan 22, 2021
1 parent
a35b32e
commit 1c5f033
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
|
||
{ | ||
// Test bad signal. | ||
assert.throws( | ||
() => dgram.createSocket({ type: 'udp4', signal: {} }), | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError' | ||
}); | ||
} | ||
|
||
{ | ||
// Test close. | ||
const controller = new AbortController(); | ||
const { signal } = controller; | ||
const server = dgram.createSocket({ type: 'udp4', signal }); | ||
server.on('close', common.mustCall()); | ||
controller.abort(); | ||
} | ||
|
||
{ | ||
// Test close with pre-aborted signal. | ||
const controller = new AbortController(); | ||
controller.abort(); | ||
const { signal } = controller; | ||
const server = dgram.createSocket({ type: 'udp4', signal }); | ||
server.on('close', common.mustCall()); | ||
} |