Skip to content

fs: add 'close' event to FSWatcher - #19900

Closed
aleclarson wants to merge 3 commits into
nodejs:masterfrom
aleclarson:patch-1
Closed

fs: add 'close' event to FSWatcher#19900
aleclarson wants to merge 3 commits into
nodejs:masterfrom
aleclarson:patch-1

Conversation

@aleclarson

Copy link
Copy Markdown
Contributor

Should process.nextTick wrap this? Are tests necessary here?

  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Apr 9, 2018
@mscdex

Copy link
Copy Markdown
Contributor

A test would be good, yes.

@cjihrig

Copy link
Copy Markdown
Contributor

Docs are needed as well.

@jasnell
jasnell requested a review from mcollinaApril 9, 2018 20:17
@mcollina

Copy link
Copy Markdown
Member

Why do you need a 'close' event? I'm not against this, I just want to understand better.
close() seems to be a synchronous operation.

@aleclarson

aleclarson commented Apr 10, 2018

Copy link
Copy Markdown
ContributorAuthor

@mcollina To keep the close logic in the same function as fs.watch(). The watcher's close method is called from multiple places.

functionwatch(root){returnfs.watch(root,(evt,file)=>{// ...}).on('close',()=>{// ...})}

Currently, I'm monkey-patching the close method.

functionwatch(root){letwatcher=fs.watch(root,(evt,file)=>{// ...})let{close}=watcherwatcher.close=function(){close.call(watcher)// ...}returnwatcher}

@mcollina

Copy link
Copy Markdown
Member

@aleclarson definitely better. Can you add a unit test?

@aleclarson

Copy link
Copy Markdown
ContributorAuthor

Added a test and docs. Note the <!-- YAML added: v --> is missing.

@mcollina

Copy link
Copy Markdown
Member

@aleclarson the <!-- YAML added: v --> should be added. Use REPLACEME as the version.

Comment threadtest/parallel/test-fs-watch.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can drop the closeCount, and just write watcher.on('close', common.mustCall());

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Does that protect against multiple calls?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes

@aleclarson

Copy link
Copy Markdown
ContributorAuthor

Good to go 👍

@mcollinamcollina 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.

LGTM

Comment threadlib/fs.js Outdated

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.

Can you wrap this in a process.nextTick()? Zalgo and all that.

@BridgeAR

Copy link
Copy Markdown
Member

Ping @aleclarson

@aleclarson

Copy link
Copy Markdown
ContributorAuthor

Now wrapped with process.nextTick

@joyeecheungjoyeecheung added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 12, 2018
@jasnell

Copy link
Copy Markdown
Member

@lpinca

Copy link
Copy Markdown
Member

Landed in 5cc948b.

@lpincalpinca closed this Apr 16, 2018
lpinca pushed a commit that referenced this pull request Apr 16, 2018
PR-URL: #19900
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
jasnell pushed a commit that referenced this pull request Apr 16, 2018
PR-URL: #19900
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
PR-URL: nodejs#19900
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fsIssues and PRs related to the fs subsystem / file system.semver-minorPRs 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.

11 participants

@aleclarson@mscdex@cjihrig@mcollina@BridgeAR@jasnell@lpinca@bnoordhuis@joyeecheung@richardlau@nodejs-github-bot