diff --git a/lib/file-list.js b/lib/file-list.js index 13129cd32..a959b9c35 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -65,7 +65,7 @@ class FileList { // So we know we are refreshing when this promise // is still pending, and we are done when it's either // resolved or rejected. - this._refreshing = Promise.resolve() + this._refreshing = null // Emit the `file_list_modified` event. // This function is debounced to the value of `autoWatchBatchDelay` @@ -131,7 +131,7 @@ class FileList { // Check if we are currently refreshing _isRefreshing () { - return this._refreshing.isPending() + return this._refreshing && this._refreshing.isPending() } // Do the actual work of refreshing @@ -139,8 +139,8 @@ class FileList { const buckets = this.buckets const matchedFiles = new Set() - let promise - promise = Promise.map(this._patterns, (patternObject) => { + let lastCompletedRefresh = this._refreshing + lastCompletedRefresh = Promise.map(this._patterns, (patternObject) => { const pattern = patternObject.pattern const type = patternObject.type @@ -195,7 +195,11 @@ class FileList { }) }) .then(() => { - if (this._refreshing !== promise) { + // When we return from this function the file processing chain will be + // complete. In the case of two fast refresh() calls, the second call + // will overwrite this._refreshing, and we want the status to reflect + // the second call and skip the modification event from the first call. + if (this._refreshing !== lastCompletedRefresh) { return this._refreshing } this.buckets = buckets @@ -203,7 +207,7 @@ class FileList { return this.files }) - return promise + return lastCompletedRefresh } // Public Interface