Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This function creates a file handle (as a Node.js [`FileHandle`](https://nodejs.
async function readFile(path) {
await using disposer = new AsyncDisposableStack();
const handle = disposer.adopt(
fs.open(path),
await fs.open(path),
async (handle) => await handle.close(),
);
const data = await handle.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This function reads a file (as a Node.js [`FileHandle`](https://nodejs.org/api/f
```js
async function readFileContents(path) {
await using disposer = new AsyncDisposableStack();
const handle = disposer.use(fs.open(path));
const handle = disposer.use(await fs.open(path));
const data = await handle.read();
return data;
// The disposer is disposed here, which causes handle to be closed too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ for await (using reader of asyncIterableOfSyncDisposables) {
```

```js
const syncIterableOfAsyncDisposables = fs
.globSync("*.txt")
.map((path) => fs.open(path, "r"));
const syncIterableOfAsyncDisposables = await Promise.all(
fs.globSync("*.txt").map((path) => fs.open(path, "r")),
);
for (await using file of syncIterableOfAsyncDisposables) {
console.log(await file.read());
}
Expand Down