@whatwg-node/server
Advanced tools
Comparing version 0.9.63 to 0.9.64-alpha-20241217102918-0325896dc8d5dcea60bb717d44cccfdb5bd69677
@@ -34,3 +34,5 @@ "use strict"; | ||
_disposableStack = new disposablestack_1.AsyncDisposableStack(); | ||
(0, utils_js_1.ensureDisposableStackRegisteredForTerminateEvents)(_disposableStack); | ||
if (options?.disposeOnProcessTerminate) { | ||
(0, utils_js_1.ensureDisposableStackRegisteredForTerminateEvents)(_disposableStack); | ||
} | ||
_disposableStack.defer(() => { | ||
@@ -67,6 +69,13 @@ if (waitUntilPromises.size > 0) { | ||
} | ||
const disposeFn = plugin[disposablestack_1.DisposableSymbols.asyncDispose] || plugin[disposablestack_1.DisposableSymbols.dispose]; | ||
if (disposeFn != null) { | ||
const disposeFn = plugin[disposablestack_1.DisposableSymbols.dispose]; | ||
if (disposeFn) { | ||
ensureDisposableStack().defer(disposeFn); | ||
} | ||
const asyncDisposeFn = plugin[disposablestack_1.DisposableSymbols.asyncDispose]; | ||
if (asyncDisposeFn) { | ||
ensureDisposableStack().defer(asyncDisposeFn); | ||
} | ||
if (plugin.onDispose) { | ||
ensureDisposableStack().defer(plugin.onDispose); | ||
} | ||
} | ||
@@ -73,0 +82,0 @@ } |
@@ -30,3 +30,5 @@ import { AsyncDisposableStack, DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
_disposableStack = new AsyncDisposableStack(); | ||
ensureDisposableStackRegisteredForTerminateEvents(_disposableStack); | ||
if (options?.disposeOnProcessTerminate) { | ||
ensureDisposableStackRegisteredForTerminateEvents(_disposableStack); | ||
} | ||
_disposableStack.defer(() => { | ||
@@ -63,6 +65,13 @@ if (waitUntilPromises.size > 0) { | ||
} | ||
const disposeFn = plugin[DisposableSymbols.asyncDispose] || plugin[DisposableSymbols.dispose]; | ||
if (disposeFn != null) { | ||
const disposeFn = plugin[DisposableSymbols.dispose]; | ||
if (disposeFn) { | ||
ensureDisposableStack().defer(disposeFn); | ||
} | ||
const asyncDisposeFn = plugin[DisposableSymbols.asyncDispose]; | ||
if (asyncDisposeFn) { | ||
ensureDisposableStack().defer(asyncDisposeFn); | ||
} | ||
if (plugin.onDispose) { | ||
ensureDisposableStack().defer(plugin.onDispose); | ||
} | ||
} | ||
@@ -69,0 +78,0 @@ } |
{ | ||
"name": "@whatwg-node/server", | ||
"version": "0.9.63", | ||
"version": "0.9.64-alpha-20241217102918-0325896dc8d5dcea60bb717d44cccfdb5bd69677", | ||
"description": "Fetch API compliant HTTP Server adapter", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -6,2 +6,10 @@ import { ServerAdapterPlugin } from './plugins/types.js'; | ||
fetchAPI?: Partial<FetchAPI>; | ||
/** | ||
* Node.js only! | ||
* | ||
* If true, the server adapter will dispose itself when the process is terminated. | ||
* If false, you have to dispose the server adapter by using the `dispose` method, | ||
* or [Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html) | ||
*/ | ||
disposeOnProcessTerminate?: boolean; | ||
} | ||
@@ -8,0 +16,0 @@ declare function createServerAdapter<TServerContext = {}, THandleRequest extends ServerAdapterRequestHandler<TServerContext> = ServerAdapterRequestHandler<TServerContext>>(serverAdapterRequestHandler: THandleRequest, options?: ServerAdapterOptions<TServerContext>): ServerAdapter<TServerContext, ServerAdapterBaseObject<TServerContext, THandleRequest>>; |
@@ -24,3 +24,3 @@ import { FetchAPI, ServerAdapterRequestHandler, type ServerAdapterInitialContext } from '../types.js'; | ||
* This hook is invoked when the server is being disposed. | ||
* The server disposal is triggered either by the request termination or the explicit server disposal. | ||
* The server disposal is triggered either by the process termination or the explicit server disposal. | ||
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html | ||
@@ -31,6 +31,12 @@ */ | ||
* This hook is invoked when the server is being disposed. | ||
* The server disposal is triggered either by the request termination or the explicit server disposal. | ||
* The server disposal is triggered either by the process termination or the explicit server disposal. | ||
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html | ||
*/ | ||
[Symbol.asyncDispose]?: () => PromiseLike<void> | void; | ||
/** | ||
* This hook is invoked when the server is being disposed. | ||
* The server disposal is triggered either by the process termination or the explicit server disposal. | ||
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html | ||
*/ | ||
onDispose?: () => PromiseLike<void> | void; | ||
} | ||
@@ -37,0 +43,0 @@ export type OnRequestHook<TServerContext> = (payload: OnRequestEventPayload<TServerContext>) => Promise<void> | void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
159223
3333