File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -2989,6 +2989,51 @@ added: v0.5.9
29892989
29902990Calls ` message.socket.setTimeout(msecs, callback) ` .
29912991
2992+ ### ` message.signal `
2993+
2994+ <!-- YAML
2995+ added: REPLACEME
2996+ -->
2997+
2998+ * Type: {AbortSignal}
2999+
3000+ An {AbortSignal} that is aborted when the underlying socket closes or the
3001+ request is destroyed. The signal is created lazily on first access — no
3002+ {AbortController} is allocated for requests that never use this property.
3003+
3004+ This is useful for cancelling downstream asynchronous work such as database
3005+ queries or ` fetch ` calls when a client disconnects mid-request.
3006+
3007+ ``` mjs
3008+ import http from ' node:http' ;
3009+
3010+ http .createServer (async (req , res ) => {
3011+ try {
3012+ const data = await fetch (' https://example.com/api' , { signal: req .signal });
3013+ res .end (JSON .stringify (await data .json ()));
3014+ } catch (err) {
3015+ if (err .name === ' AbortError' ) return ;
3016+ res .statusCode = 500 ;
3017+ res .end (' Internal Server Error' );
3018+ }
3019+ }).listen (3000 );
3020+ ```
3021+
3022+ ``` cjs
3023+ const http = require (' node:http' );
3024+
3025+ http .createServer (async (req , res ) => {
3026+ try {
3027+ const data = await fetch (' https://slow-api.com' , { signal: req .signal });
3028+ res .end (JSON .stringify (await data .json ()));
3029+ } catch (err) {
3030+ if (err .name === ' AbortError' ) return ;
3031+ res .statusCode = 500 ;
3032+ res .end (' Internal Server Error' );
3033+ }
3034+ }).listen (3000 );
3035+ ```
3036+
29923037### ` message.socket `
29933038
29943039<!-- YAML
You can’t perform that action at this time.
0 commit comments