diff --git a/lib/file-list.js b/lib/file-list.js index c73b98ca5..71f2b3639 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -150,7 +150,7 @@ List.prototype._refresh = function () { var self = this var buckets = this.buckets - return Promise.all(this._patterns.map(function (patternObject) { + var promise = Promise.map(this._patterns, function (patternObject) { var pattern = patternObject.pattern if (helper.isUrlAbsolute(pattern)) { @@ -167,7 +167,7 @@ List.prototype._refresh = function () { return } - return Promise.all(files.map(function (path) { + return Promise.map(files, function (path) { if (self._isExcluded(path)) { log.debug('Excluded file "%s"', path) return Promise.resolve() @@ -185,7 +185,7 @@ List.prototype._refresh = function () { return self._preprocess(file).then(function () { return file }) - })) + }) .then(function (files) { files = _.compact(files) @@ -195,17 +195,17 @@ List.prototype._refresh = function () { buckets.set(pattern, new Set(files)) } }) - })) - .cancellable() + }) .then(function () { + if (self._refreshing !== promise) { + return self._refreshing + } self.buckets = buckets self._emitModified(true) return self.files }) - .catch(Promise.CancellationError, function () { - // We were canceled so return the resolution of the new run - return self._refreshing - }) + + return promise } // Public Interface @@ -245,10 +245,6 @@ Object.defineProperty(List.prototype, 'files', { // Returns a promise that is resolved when the refresh // is completed. List.prototype.refresh = function () { - if (this._isRefreshing()) { - this._refreshing.cancel() - } - this._refreshing = this._refresh() return this._refreshing } diff --git a/package.json b/package.json index 2fc2d0b10..05ebc39c0 100644 --- a/package.json +++ b/package.json @@ -262,7 +262,7 @@ ], "dependencies": { "batch": "^0.5.3", - "bluebird": "^2.9.27", + "bluebird": "^3.3.0", "body-parser": "^1.12.4", "chokidar": "^1.4.1", "colors": "^1.1.0", diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 7e22c1652..5f0faa3ee 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -273,10 +273,20 @@ describe('FileList', () => { var p1 = list.refresh().then(checkResult) patternList['/some/*.js'].push('/some/c.js') - mg.statCache['/some/c.js'] = {mtime: new Date()} + mg.statCache['/some/c.js'] = {mtime: new Date(Date.now() + 5000)} var p2 = list.refresh().then(checkResult) + var called = false + var callback = (data) => { + expect(called).to.be.false + expect(data.served[0].mtime.toString()).to.not.equal(data.served[2].mtime.toString()) + expect(data.served[0].mtime.toString()).to.equal(data.served[1].mtime.toString()) + called = true + } + list._emitter.on('file_list_modified', callback) - return Promise.all([p1, p2]) + return Promise.all([p1, p2]).then(() => { + list._emitter.removeListener('file_list_modified', callback) + }) }) it('sets the mtime for all files', () => {