Skip to content

Commit

Permalink
Merge pull request #6673 from elastic/jasper/backport/6651/4.x
Browse files Browse the repository at this point in the history
[backport] PR #6651 to 4.x
  • Loading branch information
spalger committed Mar 28, 2016
2 parents 2be8934 + 6ac2c36 commit baa1d8a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/ui/public/courier/fetch/_call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/ui/public/courier/fetch/_fetch_these.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions src/ui/public/courier/fetch/request/__tests__/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/ui/public/courier/fetch/request/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
});
};

Expand Down

0 comments on commit baa1d8a

Please sign in to comment.