@@ -1938,6 +1938,9 @@ method.
1938
1938
#### ` new stream.Writable([options]) `
1939
1939
<!-- YAML
1940
1940
changes:
1941
+ - version: REPLACEME
1942
+ pr-url: https://github.com/nodejs/node/pull/36431
1943
+ description: support passing in an AbortSignal.
1941
1944
- version: v14.0.0
1942
1945
pr-url: https://github.com/nodejs/node/pull/30623
1943
1946
description: Change `autoDestroy` option default to `true`.
@@ -1985,6 +1988,7 @@ changes:
1985
1988
[ ` stream._construct() ` ] [ writable-_construct ] method.
1986
1989
* ` autoDestroy ` {boolean} Whether this stream should automatically call
1987
1990
` .destroy() ` on itself after ending. ** Default:** ` true ` .
1991
+ * ` signal ` {AbortSignal} A signal representing possible cancellation.
1988
1992
1989
1993
<!-- eslint-disable no-useless-constructor -->
1990
1994
``` js
@@ -2028,6 +2032,27 @@ const myWritable = new Writable({
2028
2032
});
2029
2033
```
2030
2034
2035
+ Calling ` abort ` on the ` AbortController ` corresponding to the passed
2036
+ ` AbortSignal ` will behave the same way as calling ` .destroy(new AbortError()) `
2037
+ on the writeable stream.
2038
+
2039
+ ``` js
2040
+ const { Writable } = require (' stream' );
2041
+
2042
+ const controller = new AbortController ();
2043
+ const myWritable = new Writable ({
2044
+ write (chunk , encoding , callback ) {
2045
+ // ...
2046
+ },
2047
+ writev (chunks , callback ) {
2048
+ // ...
2049
+ },
2050
+ signal: controller .signal
2051
+ });
2052
+ // Later, abort the operation closing the stream
2053
+ controller .abort ();
2054
+
2055
+ ```
2031
2056
#### ` writable._construct(callback) `
2032
2057
<!-- YAML
2033
2058
added: v15.0.0
@@ -2276,6 +2301,9 @@ constructor and implement the [`readable._read()`][] method.
2276
2301
#### ` new stream.Readable([options]) `
2277
2302
<!-- YAML
2278
2303
changes:
2304
+ - version: REPLACEME
2305
+ pr-url: https://github.com/nodejs/node/pull/36431
2306
+ description: support passing in an AbortSignal.
2279
2307
- version: v14.0.0
2280
2308
pr-url: https://github.com/nodejs/node/pull/30623
2281
2309
description: Change `autoDestroy` option default to `true`.
@@ -2306,6 +2334,7 @@ changes:
2306
2334
[ ` stream._construct() ` ] [ readable-_construct ] method.
2307
2335
* ` autoDestroy ` {boolean} Whether this stream should automatically call
2308
2336
` .destroy() ` on itself after ending. ** Default:** ` true ` .
2337
+ * ` signal ` {AbortSignal} A signal representing possible cancellation.
2309
2338
2310
2339
<!-- eslint-disable no-useless-constructor -->
2311
2340
``` js
@@ -2346,6 +2375,23 @@ const myReadable = new Readable({
2346
2375
});
2347
2376
```
2348
2377
2378
+ Calling ` abort ` on the ` AbortController ` corresponding to the passed
2379
+ ` AbortSignal ` will behave the same way as calling ` .destroy(new AbortError()) `
2380
+ on the readable created.
2381
+
2382
+ ``` js
2383
+ const fs = require (' fs' );
2384
+ const controller = new AbortController ();
2385
+ const read = new Readable ({
2386
+ read (size ) {
2387
+ // ...
2388
+ },
2389
+ signal: controller .signal
2390
+ });
2391
+ // Later, abort the operation closing the stream
2392
+ controller .abort ();
2393
+ ```
2394
+
2349
2395
#### ` readable._construct(callback) `
2350
2396
<!-- YAML
2351
2397
added: v15.0.0
0 commit comments