当我更改观看的文件时,fs.watch 触发了两次 [英] fs.watch fired twice when I change the watched file

查看:38
本文介绍了当我更改观看的文件时,fs.watch 触发了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 fs.watch( 'example.xml', function ( curr, prev ) {
   // on file change we can read the new xml
   fs.readFile( 'example.xml','utf8', function ( err, data ) {
     if ( err ) throw err;
     console.dir(data);
     console.log('Done');
   });
 });

输出:

  • 一些数据
  • 完成 X 1
  • 一些数据
  • 完成 X 2

这是我的使用错误还是..?

It is my usage fault or ..?

推荐答案

fs.watch api:

  1. 不稳定
  2. 已知的行为"" 关于重复通知.具体来说,windows 案例 是 windows 设计的结果,其中单个文件修改可以多次调用windows API
  1. is unstable
  2. has known "behaviour" with regards repeated notifications. Specifically, the windows case being a result of windows design, where a single file modification can be multiple calls to the windows API

这篇关于当我更改观看的文件时,fs.watch 触发了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆