@@ -50,20 +50,21 @@ describes the properties available in that options object.
50
50
- [ after] ( #after )
51
51
- [ ready] ( #ready )
52
52
- [ listen] ( #listen )
53
+ - [ ` listenTextResolver ` ] ( #listentextresolver )
53
54
- [ addresses] ( #addresses )
54
55
- [ getDefaultRoute] ( #getdefaultroute )
55
56
- [ setDefaultRoute] ( #setdefaultroute )
56
57
- [ routing] ( #routing )
57
58
- [ route] ( #route )
58
- - [ hasRoute] ( #hasRoute )
59
+ - [ hasRoute] ( #hasroute )
59
60
- [ close] ( #close )
60
- - [ decorate* ] ( #decorate )
61
+ - [ decorate\ *] ( #decorate )
61
62
- [ register] ( #register )
62
63
- [ addHook] ( #addhook )
63
64
- [ prefix] ( #prefix )
64
65
- [ pluginName] ( #pluginname )
65
66
- [ hasPlugin] ( #hasplugin )
66
- - [ listeningOrigin] ( #listeningOrigin )
67
+ - [ listeningOrigin] ( #listeningorigin )
67
68
- [ log] ( #log )
68
69
- [ version] ( #version )
69
70
- [ inject] ( #inject )
@@ -93,6 +94,7 @@ describes the properties available in that options object.
93
94
- [ defaultTextParser] ( #defaulttextparser )
94
95
- [ errorHandler] ( #errorhandler )
95
96
- [ childLoggerFactory] ( #childloggerfactory )
97
+ - [ Symbol.asyncDispose] ( #symbolasyncdispose )
96
98
- [ initialConfig] ( #initialconfig )
97
99
98
100
### ` http `
@@ -1866,6 +1868,32 @@ fastify.get('/', {
1866
1868
Fastify instance. See the [` childLoggerFactory` config option](#setchildloggerfactory)
1867
1869
for more info.
1868
1870
1871
+ #### Symbol.asyncDispose
1872
+ <a id="symbolAsyncDispose"></a>
1873
+
1874
+ ` fastify[Symbol .asyncDispose ]` is a symbol that can be used to define an
1875
+ asynchronous function that will be called when the Fastify instance is closed.
1876
+
1877
+ Its commonly used alongside the ` using` typescript keyword to ensure that
1878
+ resources are cleaned up when the Fastify instance is closed.
1879
+
1880
+ This combines perfectly inside short lived processes or unit tests, where you must
1881
+ close all fastify resources after returning from inside the function.
1882
+
1883
+ ` ` ` ts
1884
+ it (' Uses app and closes it afterwards' , async () => {
1885
+ await using app = fastify ();
1886
+ // do something with app.
1887
+ })
1888
+ ` ` `
1889
+
1890
+ In the above example, fastify is closed automatically after the test finishes.
1891
+
1892
+ Read more about the
1893
+ [ECMAScript Explicit Resource Management](https://tc39.es/proposal-explicit-resource-management)
1894
+ and the [using keyword](https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/)
1895
+ introduced in typescript 5.2.
1896
+
1869
1897
#### initialConfig
1870
1898
<a id="initial-config"></a>
1871
1899
0 commit comments