title: Wait for openCursor to finish in IndexedDB
body: <p>I have this code:</p>
  
  <pre><code>html5DB.indexedDB.addSomething = function(foo) {
      var db = html5DB.indexedDB.db;
      var trans = db.transaction(["something"], "readwrite");
      var store = trans.objectStore("something");
  
      var isExisting = IsAlreadyExist(foo);
      // How to wait for that instruction to finish?
  
      if (!isExisting){
         var request = store.put({
             "text": foo,
             "timeStamp" : new Date().getTime()
         });
      }
  };
  </code></pre>
  
  <p>I'm trying to understand how can I wait for the function <code>IsAlreadyExist</code> to finish. This function opens a cursor to iterate in the object store to determinate if a particular value exist.</p>
  
  <p>Actually, there is no error, but I can't reach the code inside the <code>if (!isExisting)</code> because the value of the variable never changes.</p>
  
  <p>This is the code of that second function:</p>
  
  <pre><code>function IsAlreadyExist(foo){
      var db = html5DB.indexedDB.db;
      var objectStore = db.transaction("something").objectStore("something");
  
      objectStore.openCursor().onsuccess = function(event) {
          var cursor = event.target.result;
  
          if (cursor) {
              if (cursor.value.text == foo)   
                  return true;
  
              cursor.continue();
         }
      };
  
      return false;
  }
  </code></pre>
  
  <p>Is there a way to wait for the end of the execution? Or maybe it is not a good way to proceed for checking if a value exist?</p>