Skip to content

fs: add fsPromises.watch() - #37179

Closed
jasnell wants to merge 2 commits into
nodejs:masterfrom
jasnell:async-fs-watch
Closed

jasnell wants to merge 2 commits into
nodejs:masterfrom
jasnell:async-fs-watch

Conversation

@jasnell

@jasnell jasnell commented Feb 2, 2021

Copy link
Copy Markdown
Member

An alternative to fs.watch() that returns an AsyncIterator

const { watch } = require('fs/promises');

(async () => {

  const ac = new AbortController();
  const { signal } = ac;
  setTimeout(() => ac.abort(), 10000);

  const watcher = watch('file.txt', { signal });

  for await (const { eventType, filename } of watcher) {
    console.log(eventType, filename);
  }

})()

Signed-off-by: James M Snell jasnell@gmail.com

@jasnell jasnell added fs Issues and PRs related to file-system APIs and the fs module. semver-minor PRs that contain new features and should be released in the next minor version. promises Issues and PRs related to ECMAScript promises. labels Feb 2, 2021
Comment thread doc/api/fs.md Outdated
Comment thread doc/api/fs.md Outdated
Comment thread doc/api/fs.md Outdated
Comment thread doc/api/fs.md Outdated
Comment thread lib/internal/fs/watchers.js Outdated
Comment thread lib/internal/fs/watchers.js Outdated
Comment thread lib/internal/fs/watchers.js Outdated
Comment thread lib/internal/fs/watchers.js Outdated

@benjamingr benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start and interesting API.

LMK if you'd like me to PR signal support for fs.watch or help otherwise.

Comment thread lib/internal/fs/watchers.js Outdated
Comment thread lib/internal/fs/watchers.js Outdated
@nodejs-github-bot

This comment has been minimized.

Comment thread test/parallel/test-fs-promises-watch.js Outdated

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

ghost commented Feb 2, 2021 •

Copy link
Copy Markdown
Collaborator

@jasnell jasnell added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Feb 2, 2021
James M Snell added 2 commits February 15, 2021 06:59
An alternative to `fs.watch()` that returns an `AsyncIterator`

```js
const { watch } = require('fs/promises');

(async () => {

  const ac = new AbortController();
  const { signal } = ac;
  setTimeout(() => ac.abort(), 10000);

  const watcher = watch('file.txt', { signal });

  for await (const { eventType, filename } of watcher) {
    console.log(eventType, filename);
  }

})()
```

Signed-off-by: James M Snell <jasnell@gmail.com>
@nodejs-github-bot

ghost commented Feb 15, 2021 •

Copy link
Copy Markdown
Collaborator

@jasnell

ghost commented Feb 15, 2021

Copy link
Copy Markdown
Member Author

Landed in 9803729

@jasnell jasnell closed this Feb 15, 2021
@jasnell jasnell added the notable-change PRs with changes that should be highlighted in changelogs. label Feb 15, 2021
This was referenced Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. fs Issues and PRs related to file-system APIs and the fs module. notable-change PRs with changes that should be highlighted in changelogs. promises Issues and PRs related to ECMAScript promises. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants