Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions ext/node/polyfills/_fs/_fs_close.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
// Copyright 2018-2025 the Deno authors. MIT license.

// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials

import type { CallbackWithError } from "ext:deno_node/_fs/_fs_common.ts";
import {
type CallbackWithError,
makeCallback,
} from "ext:deno_node/_fs/_fs_common.ts";
import { getValidatedFd } from "ext:deno_node/internal/fs/utils.mjs";
import { core } from "ext:core/mod.js";
import { core, primordials } from "ext:core/mod.js";

const {
Error,
ErrorPrototype,
ObjectPrototypeIsPrototypeOf,
} = primordials;

export function close(fd: number, callback: CallbackWithError) {
fd = getValidatedFd(fd);
callback = makeCallback(callback);
setTimeout(() => {
let error = null;
try {
// TODO(@littledivy): Treat `fd` as real file descriptor. `rid` is an
// implementation detail and may change.
core.close(fd);
} catch (err) {
error = err instanceof Error ? err : new Error("[non-error thrown]");
error = ObjectPrototypeIsPrototypeOf(ErrorPrototype, err)
? err as Error
: new Error("[non-error thrown]");
}
callback(error);
}, 0);
Expand Down
Loading