-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
onDispose
and other disposal improvements (#1899)
- Loading branch information
Showing
4 changed files
with
102 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
'@whatwg-node/server': patch | ||
--- | ||
|
||
- New `onDispose` hook which is alias of `Symbol.asyncDispose` for Explicit Resource Management | ||
- Registration of the server adapter's disposal to the global process termination listener is now opt-in and configurable. | ||
|
||
```ts | ||
const plugin: ServerAdapterPlugin = { | ||
onDispose() { | ||
console.log('Server adapter is disposed'); | ||
} | ||
}; | ||
|
||
const serverAdapter = createServerAdapter(() => new Response('Hello world!'), { | ||
plugins: [plugin], | ||
// Register the server adapter's disposal to the global process termination listener | ||
// Then the server adapter will be disposed when the process exit signals only in Node.js! | ||
disposeOnProcessTerminate: true | ||
}); | ||
|
||
await serverAdapter.dispose(); | ||
// Prints 'Server adapter is disposed' | ||
``` |
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