Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update abort signal in fs promise api example #38669

Closed
wants to merge 5 commits into from
Closed
Changes from 3 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
15 changes: 11 additions & 4 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,15 @@ import { readFile } from 'fs/promises';

try {
const controller = new AbortController();
const signal = controller.signal;
readFile(fileName, { signal });
const { signal } = controller;
const promise = readFile(fileName, { signal });

// Abort the request
// Abort the request before the promise settles.
controller.abort();

aduh95 marked this conversation as resolved.
Show resolved Hide resolved
await promise;
} catch (err) {
// When a request is aborted - err is an AbortError
console.error(err);
}
```
Expand Down Expand Up @@ -1316,8 +1319,12 @@ try {
const controller = new AbortController();
const { signal } = controller;
const data = new Uint8Array(Buffer.from('Hello Node.js'));
writeFile('message.txt', data, { signal });
const promise = writeFile('message.txt', data, { signal });

// Abort the request before the promise settles.
controller.abort();

aduh95 marked this conversation as resolved.
Show resolved Hide resolved
await promise;
} catch (err) {
// When a request is aborted - err is an AbortError
console.error(err);
Expand Down