I am trying to pass the variable I get from chrome.storage.local.get to another global variable delayMilliSeconds
so I can use it in multiple functions. I know that the delay
is only inside the scope of chrome.storage.local.get and is asynchronous, however, is there a way to pass this outside the scope?
var delay;
chrome.storage.local.get('updateDelayValueTo', function(result){
delay = result.updateDelayValueTo; //I am getting this correctly
console.log("delay is: " + delay); //10000
});
function runMyCalculation() {
var delayMilliSeconds = Math.floor((Math.random() * delay) + 1);
// Run other code/functions, which depends on "delayMilliSeconds"
functionOne(delayMilliSeconds);
}
functionOne(delayMilliSeconds) {
//use delayMilliSeconds here
if(functionTwo()){
setTimeout(functionOne,delayMilliSeconds);
console.log("delay in here is: " + delayMilliSeconds);
}
}
functionTwo() {
//and here..
while(ButtonIsClicked){
console.log("delay in here is: " + delayMilliSeconds);
ButtonIsClicked logic...
}
}
console.log
delay down here is: 260
09:36:22.812 content_script.js:83 delay down here is: 260
09:36:22.813 content_script.js:15 delay is: 1000
09:36:23.074 content_script.js:79 delay down here is: undefined
09:36:23.087 content_script.js:83 delay down here is: undefined
09:36:23.089 content_script.js:79 delay down here is: undefined
09:36:23.089 content_script.js:83 delay down here is: undefined