From 7617279f68507642fdc7eb0083916f3c6c2a28cb Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Tue, 17 Jul 2018 16:37:18 -0700 Subject: [PATCH] refactor(filelist): rename promise -> lastCompletedRefresh and remove unused promise (#3060) --- lib/file-list.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/file-list.js b/lib/file-list.js index 887a9d71e..02d0bacdc 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -29,7 +29,8 @@ class FileList { this.buckets = new Map() - this._refreshing = Promise.resolve() + // A promise that is pending if and only if we are active in this.refresh_() + this._refreshing = null const emit = () => { this._emitter.emit('file_list_modified', this.files) @@ -65,8 +66,8 @@ class FileList { _refresh () { 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 @@ -113,14 +114,18 @@ 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._emitModified(true) return this.files }) - return promise + return lastCompletedRefresh } get files () {