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 414b84c commit 9cf8b14
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ class FileList {

this.buckets = new Map()

this._refreshing = Promise.resolve()

// Internal tracker if we are refreshing.
// When a refresh is triggered this gets set
// to the promise that `this._refresh` returns.
// 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 = null

const emit = () => {
this._emitter.emit('file_list_modified', this.files)
Expand Down Expand Up @@ -65,8 +72,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

Expand Down Expand Up @@ -113,14 +120,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 () {
Expand Down

0 comments on commit 9cf8b14

Please sign in to comment.