diff --git a/src/ui/public/courier/fetch/_call_client.js b/src/ui/public/courier/fetch/_call_client.js index 1cec794512c33..8cab455a0cb5c 100644 --- a/src/ui/public/courier/fetch/_call_client.js +++ b/src/ui/public/courier/fetch/_call_client.js @@ -16,6 +16,8 @@ define(function (require) { var executable = statuses.filter(isRequest); var execCount = executable.length; + if (!execCount) return Promise.resolve([]); + // resolved by respond() var esPromise; var defer = Promise.defer(); diff --git a/src/ui/public/courier/fetch/_fetch_these.js b/src/ui/public/courier/fetch/_fetch_these.js index a629c9920187f..7b96dadae4689 100644 --- a/src/ui/public/courier/fetch/_fetch_these.js +++ b/src/ui/public/courier/fetch/_fetch_these.js @@ -23,22 +23,26 @@ define(function (require) { } function fetchWithStrategy(strategy, requests) { + function replaceAbortedRequests() { + requests = requests.map(r => r.aborted ? ABORTED : r); + } - requests = requests.map(function (req) { - return req.aborted ? ABORTED : req; - }); - + replaceAbortedRequests(); return startRequests(requests) .then(function () { + replaceAbortedRequests(); return callClient(strategy, requests); }) .then(function (responses) { + replaceAbortedRequests(); return callResponseHandlers(requests, responses); }) .then(function (responses) { + replaceAbortedRequests(); return continueIncomplete(strategy, requests, responses, fetchWithStrategy); }) .then(function (responses) { + replaceAbortedRequests(); return responses.map(function (resp) { switch (resp) { case ABORTED: diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented.js b/src/ui/public/courier/fetch/request/__tests__/segmented.js index 7edfdd69190a1..a3882bc82fbbb 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented.js @@ -29,9 +29,7 @@ describe('ui/courier/fetch/request/segmented', () => { expect(returned.then).to.be.Function; }); - it('does not call super.start() until promise is resolved', () => { - expect(searchReqStart.called).to.be(false); - $rootScope.$apply(); + it('calls super.start() synchronously', () => { expect(searchReqStart.called).to.be(true); }); }); diff --git a/src/ui/public/courier/fetch/request/segmented.js b/src/ui/public/courier/fetch/request/segmented.js index 13ace5fcc0238..f7741b0ba584a 100644 --- a/src/ui/public/courier/fetch/request/segmented.js +++ b/src/ui/public/courier/fetch/request/segmented.js @@ -39,6 +39,8 @@ define(function (require) { SegmentedReq.prototype.start = function () { var self = this; + SearchReq.prototype.start.call(this); + this._complete = []; this._active = null; this._segments = []; @@ -58,12 +60,12 @@ define(function (require) { // parameters via the handle if (_.isFunction(this._initFn)) this._initFn(this._handle); return this._createQueue().then(function (queue) { + if (self.stopped) return; + self._all = queue.slice(0); // Send the initial fetch status self._reportStatus(); - - return SearchReq.prototype.start.call(self); }); };