@@ -30,6 +30,8 @@ NodeWatchFileSystem.prototype.watch = function(files, dirs, startTime, delay, ca
3030 var filesModified = { } ;
3131 var dirsModified = { } ;
3232
33+ var lastChangeTime ;
34+
3335 startTime = Math . floor ( startTime / 1000 ) * 1000 ; // only 1 second accuracy
3436
3537 var directories = { } ;
@@ -170,6 +172,7 @@ NodeWatchFileSystem.prototype.watch = function(files, dirs, startTime, delay, ca
170172
171173 callbackUndelayed ( ) ;
172174 if ( delay ) {
175+ lastChangeTime = Date . now ( ) ;
173176 change = restartDelay ;
174177 timeout = setTimeout ( onTimeout , delay ) ;
175178 } else onTimeout ( ) ;
@@ -180,6 +183,7 @@ NodeWatchFileSystem.prototype.watch = function(files, dirs, startTime, delay, ca
180183
181184 callbackUndelayed ( ) ;
182185 if ( delay ) {
186+ lastChangeTime = Date . now ( ) ;
183187 change = restartDelay ;
184188 timeout = setTimeout ( onTimeout , delay ) ;
185189 } else {
@@ -191,6 +195,7 @@ NodeWatchFileSystem.prototype.watch = function(files, dirs, startTime, delay, ca
191195 }
192196
193197 function restartDelay ( ) {
198+ lastChangeTime = Date . now ( ) ;
194199 clearTimeout ( timeout ) ;
195200 timeout = setTimeout ( onTimeout , delay ) ;
196201 }
@@ -199,6 +204,12 @@ NodeWatchFileSystem.prototype.watch = function(files, dirs, startTime, delay, ca
199204
200205 // 7.
201206 function onTimeout ( ) {
207+ var nextSecond = Math . ceil ( lastChangeTime / 1000 ) * 1000 ;
208+ var timeToNextSecond = nextSecond - Date . now ( ) ;
209+ if ( timeToNextSecond > 0 ) {
210+ setTimeout ( onTimeout , timeToNextSecond ) ;
211+ return ;
212+ }
202213 change = function ( ) { } ;
203214 if ( closed ) return ;
204215 var outdatedFiles = Object . keys ( filesModified ) . sort ( ) ;
0 commit comments