Skip to content

Commit

Permalink
refactor(filelist): rename promise -> lastCompletedRefresh and remove…
Browse files Browse the repository at this point in the history
… unused promise
  • Loading branch information
johnjbarton committed Jun 20, 2018
1 parent b99f03f commit 2c8082f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -131,16 +131,16 @@ 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
_refresh () {
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

Expand Down Expand Up @@ -195,15 +195,19 @@ 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
this._emitModified(true)
return this.files
})

return promise
return lastCompletedRefresh
}

// Public Interface
Expand Down

0 comments on commit 2c8082f

Please sign in to comment.