mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
events: allow use of AbortController with once
Allows an AbortSignal to be passed in to events.once() to cancel waiting on an event. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/34911 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
37a8179673
commit
883fc779b6
4 changed files with 179 additions and 4 deletions
|
@ -216,6 +216,15 @@ const validateCallback = hideStackFrames((callback) => {
|
|||
throw new ERR_INVALID_CALLBACK(callback);
|
||||
});
|
||||
|
||||
const validateAbortSignal = hideStackFrames((signal, name) => {
|
||||
if (signal !== undefined &&
|
||||
(signal === null ||
|
||||
typeof signal !== 'object' ||
|
||||
!('aborted' in signal))) {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
isInt32,
|
||||
isUint32,
|
||||
|
@ -234,4 +243,5 @@ module.exports = {
|
|||
validateString,
|
||||
validateUint32,
|
||||
validateCallback,
|
||||
validateAbortSignal,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue