From 3a8586bee28a7a87d53e80f31a1a6340928e7fd7 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 25 Jun 2023 14:18:54 +0300 Subject: [PATCH] fs, stream: initial `Symbol.dispose` and `Symbol.asyncDispose` support Co-authored-by: Benjamin Gruenbaum PR-URL: https://github.com/nodejs/node/pull/48518 Backport-PR-URL: https://github.com/nodejs/node/pull/49598 Reviewed-By: Robert Nagy Reviewed-By: Erick Wendel Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina --- doc/api/fs.md | 10 ++++++++ doc/api/stream.md | 11 +++++++++ lib/internal/fs/promises.js | 5 ++++ lib/internal/per_context/primordials.js | 6 +++++ lib/internal/process/pre_execution.js | 13 +++++++++++ lib/internal/streams/readable.js | 11 +++++++++ .../test-fs-promises-file-handle-dispose.js | 12 ++++++++++ test/parallel/test-stream-readable-dispose.js | 23 +++++++++++++++++++ typings/primordials.d.ts | 2 ++ 9 files changed, 93 insertions(+) create mode 100644 test/parallel/test-fs-promises-file-handle-dispose.js create mode 100644 test/parallel/test-stream-readable-dispose.js diff --git a/doc/api/fs.md b/doc/api/fs.md index 261d6c532eb952..e5056a35d32089 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -813,6 +813,16 @@ On Linux, positional writes don't work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file. +#### `filehandle[Symbol.asyncDispose]()` + + + +> Stability: 1 - Experimental + +An alias for `filehandle.close()`. + ### `fsPromises.access(path[, mode])` + +> Stability: 1 - Experimental + +Calls [`readable.destroy()`][readable-destroy] with an `AbortError` and returns +a promise that fulfills when the stream is finished. + ##### `readable.compose(stream[, options])`