Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-02-01 22:55:12 +0300
committerMichaël Zasso <targos@protonmail.com>2021-05-01 13:25:05 +0300
commit92348a9216876d274d48996664abe53c2f11880e (patch)
treeb46fc63ce10b39cf969a85bfa8f3811db8d9c995 /lib
parentcb632e40403f9d59061f6dab9199e3ae2d9e962d (diff)
fs: use a default callback for fs.close()
The `fs.close()` function requires a callback. Most often the only thing that callback does is check and rethrow the error if one occurs. To eliminate common boilerplate, make the callback optional with a default that checks and rethrows the error as an uncaught exception. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/37174 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 8d27c5b2d92..3d6dc93354b 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -434,9 +434,14 @@ function readFileSync(path, options) {
return buffer;
}
-function close(fd, callback) {
+function defaultCloseCallback(err) {
+ if (err != null) throw err;
+}
+
+function close(fd, callback = defaultCloseCallback) {
validateInt32(fd, 'fd', 0);
- callback = makeCallback(callback);
+ if (callback !== defaultCloseCallback)
+ callback = makeCallback(callback);
const req = new FSReqCallback();
req.oncomplete = callback;