@whatwg-node/server
Advanced tools
Comparing version 0.9.58 to 0.9.59-rc-20241125184425-a8fccc28b169011604dfa3149cf1c7a317b1f279
@@ -31,29 +31,20 @@ "use strict"; | ||
const waitUntilPromises = new Set(); | ||
const disposableStack = new disposablestack_1.AsyncDisposableStack(); | ||
const signals = new Set(); | ||
function registerSignal(signal) { | ||
signals.add(signal); | ||
signal.addEventListener('abort', () => { | ||
signals.delete(signal); | ||
}); | ||
} | ||
disposableStack.defer(() => { | ||
for (const signal of signals) { | ||
signal.sendAbort(); | ||
} | ||
}); | ||
disposableStack.defer(() => { | ||
if (waitUntilPromises.size > 0) { | ||
return Promise.allSettled(waitUntilPromises).then(() => { | ||
waitUntilPromises.clear(); | ||
}, () => { | ||
waitUntilPromises.clear(); | ||
let _disposableStack; | ||
function ensureDisposableStack() { | ||
if (!_disposableStack) { | ||
_disposableStack = new disposablestack_1.AsyncDisposableStack(); | ||
(0, utils_js_1.ensureDisposableStackRegisteredForTerminateEvents)(_disposableStack); | ||
_disposableStack.defer(() => { | ||
if (waitUntilPromises.size > 0) { | ||
return Promise.allSettled(waitUntilPromises).then(() => { | ||
waitUntilPromises.clear(); | ||
}, () => { | ||
waitUntilPromises.clear(); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
return _disposableStack; | ||
} | ||
function waitUntil(promiseLike) { | ||
// If it is a Node.js environment, we should register the disposable stack to handle process termination events | ||
if (globalThis.process) { | ||
(0, utils_js_1.ensureDisposableStackRegisteredForTerminateEvents)(disposableStack); | ||
} | ||
waitUntilPromises.add(promiseLike); | ||
@@ -77,3 +68,3 @@ promiseLike.then(() => { | ||
if (disposeFn != null) { | ||
disposableStack.defer(disposeFn); | ||
ensureDisposableStack().defer(disposeFn); | ||
} | ||
@@ -153,3 +144,3 @@ } | ||
const serverContext = ctx.length > 1 ? (0, utils_js_1.completeAssign)(...ctx) : ctx[0] || {}; | ||
const request = (0, utils_js_1.normalizeNodeRequest)(nodeRequest, fetchAPI, registerSignal); | ||
const request = (0, utils_js_1.normalizeNodeRequest)(nodeRequest, fetchAPI); | ||
return handleRequest(request, serverContext); | ||
@@ -201,3 +192,2 @@ } | ||
const signal = new utils_js_1.ServerAdapterRequestAbortSignal(); | ||
registerSignal(signal); | ||
const originalResEnd = res.end.bind(res); | ||
@@ -321,6 +311,8 @@ let resEnded = false; | ||
handle: genericRequestHandler, | ||
disposableStack, | ||
get disposableStack() { | ||
return ensureDisposableStack(); | ||
}, | ||
[disposablestack_1.DisposableSymbols.asyncDispose]() { | ||
if (!disposableStack.disposed) { | ||
return disposableStack.disposeAsync(); | ||
if (_disposableStack && !_disposableStack.disposed) { | ||
return _disposableStack.disposeAsync(); | ||
} | ||
@@ -330,4 +322,4 @@ return (0, uwebsockets_js_1.fakePromise)(undefined); | ||
dispose() { | ||
if (!disposableStack.disposed) { | ||
return disposableStack.disposeAsync(); | ||
if (_disposableStack && !_disposableStack.disposed) { | ||
return _disposableStack.disposeAsync(); | ||
} | ||
@@ -334,0 +326,0 @@ return (0, uwebsockets_js_1.fakePromise)(undefined); |
@@ -550,3 +550,3 @@ "use strict"; | ||
} | ||
const terminateEvents = ['SIGINT', 'SIGTERM', 'exit']; | ||
const terminateEvents = ['SIGINT', 'exit']; | ||
const disposableStacks = new Set(); | ||
@@ -553,0 +553,0 @@ let eventListenerRegistered = false; |
@@ -27,29 +27,20 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
const waitUntilPromises = new Set(); | ||
const disposableStack = new AsyncDisposableStack(); | ||
const signals = new Set(); | ||
function registerSignal(signal) { | ||
signals.add(signal); | ||
signal.addEventListener('abort', () => { | ||
signals.delete(signal); | ||
}); | ||
} | ||
disposableStack.defer(() => { | ||
for (const signal of signals) { | ||
signal.sendAbort(); | ||
} | ||
}); | ||
disposableStack.defer(() => { | ||
if (waitUntilPromises.size > 0) { | ||
return Promise.allSettled(waitUntilPromises).then(() => { | ||
waitUntilPromises.clear(); | ||
}, () => { | ||
waitUntilPromises.clear(); | ||
let _disposableStack; | ||
function ensureDisposableStack() { | ||
if (!_disposableStack) { | ||
_disposableStack = new AsyncDisposableStack(); | ||
ensureDisposableStackRegisteredForTerminateEvents(_disposableStack); | ||
_disposableStack.defer(() => { | ||
if (waitUntilPromises.size > 0) { | ||
return Promise.allSettled(waitUntilPromises).then(() => { | ||
waitUntilPromises.clear(); | ||
}, () => { | ||
waitUntilPromises.clear(); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
return _disposableStack; | ||
} | ||
function waitUntil(promiseLike) { | ||
// If it is a Node.js environment, we should register the disposable stack to handle process termination events | ||
if (globalThis.process) { | ||
ensureDisposableStackRegisteredForTerminateEvents(disposableStack); | ||
} | ||
waitUntilPromises.add(promiseLike); | ||
@@ -73,3 +64,3 @@ promiseLike.then(() => { | ||
if (disposeFn != null) { | ||
disposableStack.defer(disposeFn); | ||
ensureDisposableStack().defer(disposeFn); | ||
} | ||
@@ -149,3 +140,3 @@ } | ||
const serverContext = ctx.length > 1 ? completeAssign(...ctx) : ctx[0] || {}; | ||
const request = normalizeNodeRequest(nodeRequest, fetchAPI, registerSignal); | ||
const request = normalizeNodeRequest(nodeRequest, fetchAPI); | ||
return handleRequest(request, serverContext); | ||
@@ -197,3 +188,2 @@ } | ||
const signal = new ServerAdapterRequestAbortSignal(); | ||
registerSignal(signal); | ||
const originalResEnd = res.end.bind(res); | ||
@@ -317,6 +307,8 @@ let resEnded = false; | ||
handle: genericRequestHandler, | ||
disposableStack, | ||
get disposableStack() { | ||
return ensureDisposableStack(); | ||
}, | ||
[DisposableSymbols.asyncDispose]() { | ||
if (!disposableStack.disposed) { | ||
return disposableStack.disposeAsync(); | ||
if (_disposableStack && !_disposableStack.disposed) { | ||
return _disposableStack.disposeAsync(); | ||
} | ||
@@ -326,4 +318,4 @@ return fakePromise(undefined); | ||
dispose() { | ||
if (!disposableStack.disposed) { | ||
return disposableStack.disposeAsync(); | ||
if (_disposableStack && !_disposableStack.disposed) { | ||
return _disposableStack.disposeAsync(); | ||
} | ||
@@ -330,0 +322,0 @@ return fakePromise(undefined); |
@@ -527,3 +527,3 @@ export function isAsyncIterable(body) { | ||
} | ||
const terminateEvents = ['SIGINT', 'SIGTERM', 'exit']; | ||
const terminateEvents = ['SIGINT', 'exit']; | ||
const disposableStacks = new Set(); | ||
@@ -530,0 +530,0 @@ let eventListenerRegistered = false; |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.9.58", | ||
"version": "0.9.59-rc-20241125184425-a8fccc28b169011604dfa3149cf1c7a317b1f279", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153534
3268