title: How to use asynchronous method in a synchronous method
body: <p>I developed a game in web technology that store the data in LocalStorage. The LocalStorage works as synchronous.To set and get the values from localstorage as</p>
  
  <p>// set the value in localstorage</p>
  
  <pre><code>localStorage.setItem('Key', "value");
  </code></pre>
  
  <p>// get the value from localstorage </p>
  
  <pre><code>var localValue = localStorage.getItem('Key');
  </code></pre>
  
  <p>There is 5MB limit in localstorage. After play the some level, localstorage filled completely. I need a large area for storage at client side.</p>
  
  <p>My first question is that <strong>“What is the best way to solve this problem?”</strong></p>
  
  <p>To solve above problem,I find the <a href="https://github.com/tantaman/LargeLocalStorage" rel="nofollow">LargeLocalStorage</a>.It is worked as asynchronous.</p>
  
  <p>// set the value in LargeLocalStorage</p>
  
  <pre><code>storage.setContents('docKey', "the contents...").then(function() {alert('doc created/updated');});
  </code></pre>
  
  <p>// get the value from LargeLocalStorage</p>
  
  <pre><code>storage.getContents('myDoc').then(function(content){//content is value for particular key});
  </code></pre>
  
  <p>Is there is any way that make these method synchronous because my all code is according to the synchronous localstorage. It will take a lot of time to change the whole logic according to the asynchronous LargeLocalStorage.</p>
  
  <p>I am currently try to override the setItem and getItem method of localstorage as :</p>
  
  <pre><code>localStorage.__proto__.getItem = function(key) {
  
  var returnVal;
  
  storage.getContents(key).then(function(content) {
          returnVal = content;
  
      });
  return returnVal;//it returns undefined
  }
  </code></pre>
  
  <p>Above override method returns undefined value due to asynchronous behaviour.</p>
  
  <p>Please help me to get value synchronous using above methods.</p>
  
  <p>Thanks in advance.</p>