Merge pull request #6677 from elastic/jasper/backport/6651/6673/4.5

[backport] PR #6651 to 4.5
This commit is contained in:
Court Ewing 2016-03-28 13:42:06 -04:00
commit 60d8a88ae5
4 changed files with 15 additions and 9 deletions

View file

@ -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();

View file

@ -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:

View file

@ -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);
});
});

View file

@ -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);
});
};