From 433f8a919cd4ebcbc4bf8319dd8e344411af5f6d Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 9 Jul 2018 13:49:22 -0700 Subject: [PATCH] Declare SearchRequest state variables in constructor. (#20578) --- .../request/search_request/search_request.js | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/ui/public/courier/fetch/request/search_request/search_request.js b/src/ui/public/courier/fetch/request/search_request/search_request.js index c1f0d25e99942..b1c075f4f1b97 100644 --- a/src/ui/public/courier/fetch/request/search_request/search_request.js +++ b/src/ui/public/courier/fetch/request/search_request/search_request.js @@ -27,38 +27,65 @@ export function SearchRequestProvider(Promise) { if (!errorHandler) { throw new Error('errorHandler is required'); } + this.errorHandler = errorHandler; this.source = source; this.defer = defer || Promise.defer(); this.abortedDefer = Promise.defer(); this.type = 'search'; + + // Track execution time. + this.moment = undefined; + this.ms = undefined; + + // Lifecycle state. + this.started = false; + this.stopped = false; + this._isFetchRequested = false; + searchRequestQueue.add(this); } /** - * Called by the loopers to find requests that should be sent to the - * fetch() module. When a module is sent to fetch() it's _fetchRequested flag - * is set, and this consults that flag so requests are not send to fetch() + * Called by the searchPoll to find requests that should be sent to the + * fetchSoon module. When a module is sent to fetchSoon its _isFetchRequested flag + * is set, and this consults that flag so requests are not send to fetchSoon * multiple times. * * @return {Boolean} */ canStart() { - return !this._fetchRequested && !this.stopped && !this.source._fetchDisabled; + if (this.source._fetchDisabled) { + return false; + } + + if (this.stopped) { + return false; + } + + if (this._isFetchRequested) { + return false; + } + + return true; } /** - * Used to find requests that were previously sent to the fetch() module but + * Used to find requests that were previously sent to the fetchSoon module but * have not been started yet, so they can be started. * * @return {Boolean} */ isFetchRequestedAndPending() { - return this._fetchRequested && !this.started; + if (this.started) { + return false; + } + + return this._isFetchRequested; } /** - * Called by the fetch() module when this request has been sent to + * Called by the fetchSoon module when this request has been sent to * be fetched. At that point the request is somewhere between `ready-to-start` * and `started`. The fetch module then waits a short period of time to * allow requests to build up in the request queue, and then immediately @@ -67,7 +94,7 @@ export function SearchRequestProvider(Promise) { * @return {undefined} */ _setFetchRequested() { - this._fetchRequested = true; + this._isFetchRequested = true; } start() {