From 64bfd1e783dde0ed935cf51cce40601cedb4240f 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 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 | 25 ++++++++++++++----- 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, 99 insertions(+), 6 deletions(-) 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 8007290b3fcb82..31dcf0b6ab3406 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -817,6 +817,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])`