Answer the question
In order to leave comments, you need to log in
How to get a synchronous function from an asynchronous function?
in the plugin I need to get data from localstorage
function getAccessKeyId() {
var a;
chrome.storage.local.get(null, function (result) {
a = result.AWSAccessKeyId
})
console.log(a)
return AWS_ACCESS_KEY;
}
Answer the question
In order to leave comments, you need to log in
If it is possible to use ES7, then you can use async / await, if not, you can use promises
function getAccessKeyId() {
return new Promise(function(resolve){
chrome.storage.local.get(null, function (result) {
resolve(result.AWSAccessKeyId);
});
});
};
getAccessKeyId().then(function(key){
console.log(key);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question