From e164fb24dc39d005ccaea17fe1405901a9eaf5fd Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Wed, 20 Jul 2016 20:12:01 -0700 Subject: [PATCH] make sure only one flag settings request is in progress --- src/Requestor.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Requestor.js b/src/Requestor.js index 1b223b8f..59e1de9b 100644 --- a/src/Requestor.js +++ b/src/Requestor.js @@ -17,15 +17,24 @@ function fetchJSON(endpoint, callback) { xhr.open('GET', endpoint); xhr.send(); + + return xhr; } +var flagSettingsRequest; + function Requestor(baseUrl, environment) { var requestor = {}; requestor.fetchFlagSettings = function(user, hash, callback) { var data = utils.base64URLEncode(JSON.stringify(user)); var endpoint = [baseUrl, '/sdk/eval/', environment, '/users/', data, hash ? '?h=' + hash : ''].join(''); - fetchJSON(endpoint, callback); + + if (flagSettingsRequest) { + flagSettingsRequest.abort(); + } + + flagSettingsRequest = fetchJSON(endpoint, callback); }; requestor.fetchGoals = function(callback) {