Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:13:14+00:00 2026-06-08T14:13:14+00:00

In the getCursor_ function below, please explain how I could determine if IndexedDb has

  • 0

In the getCursor_ function below, please explain how I could determine if IndexedDb has opened and if not re-run function once it has? The getCursor_ runs correctly. However, since all of these calls are asynchronous, the function fails when executing before the database has completed opening.

This code is executed in a separate process:

var ixDb;
var ixDbRequest;

ixDbRequest = window.indexedDB.open(dbName, dbVersion);

ixDbRequest.onsuccess = function (e) {
            ixDb = ixDbRequest.result || e.result;
}; 

The getCursor_ function below works fine unless ixDbRequest has not completed execution. I figured out how to test for that, but I am not sure how to wait in the instance where the open database request is still running.

function getCursor_(objectStoreName) {
    if (!ixDb) {
        if (ixDbRequest) {
            // "Database is still opening.  Need code to wait or re-run 
            // once completed here.
            // I tried the following with no luck:
            ixDbRequest.addEventListener ("success",
                getCursor_(objectStoreName), false); 
            return;
        }
    }

    var transaction = ixDb.transaction(objectStoreName, 
                                       IDBTransaction.READ_ONLY);
    var objectStore = transaction.objectStore(objectStoreName);  
    try{
        var request = objectStore.openCursor(); 
        return request;
    }
    catch(e){
        console.log('IndexedDB Error' + '(' + e.code + '): ' + e.message);
    }
}

UPDATE BELOW:

The answer from @Dangerz definitely helped put me on the right track. However, since the function call is asynchronous, I also ended up having to add a callback in order to actually be able to use the cursor once the “success” event finally fired, and I was able to get the requested IndexedDb cursor. The final working function is below (re-factored slightly to remove the negative logic above “if(!ixDb)” . I am totally open to suggestions, if anyone sees room for improvement!

//****************************************************************************
//Function getCursor - Returns a cursor for the requested ObjectStore
//  objectStoreName  - Name of the Object Store / Table "MyOsName" 
//         callback  - Name of the function to call and pass the cursor 
//                     request back to upon completion.
//                     Ex. getCursor_("ObjectStore_Name", MyCallBackFunction);
//                     Function MyCallBackFunction(CursorRequestObj) { 
//                     CursorRequestObj.onsuccess = 
//                               function() {//do stuff here};
//                     }
//****************************************************************************
function getCursor_(objectStoreName, callback) {
  //The the openCursor call is asynchronous, so we must check to ensure a 
  // database connection has been established and then provide the cursor 
  // via callback. 
  if (ixDb) {
      var transaction = 
        ixDb.transaction(objectStoreName, IDBTransaction.READ_ONLY);
      var objectStore = transaction.objectStore(objectStoreName); 

      try{
        var request = objectStore.openCursor(); 
        callback(request);
        console.log('ixDbEz: Getting cursor request for ' 
                    + objectStoreName + ".");
      }
      catch(e){
        console.log('ixDbEz Error' + ' getCursor:(' 
                    + e.code + '): ' + e.message);
      } 
  }
  else { 
    if (ixDbRequest) {
      ixDbRequest.addEventListener ("success"
                    , function() { getCursor_(objectStoreName, callback); }
                    , false);
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:13:17+00:00Added an answer on June 8, 2026 at 2:13 pm

    Change your addEventListener line to:

    ixDbRequest.addEventListener ("success", function() { getCursor_(objectStoreName) }, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run my activity that has the list view I am trying to
Anyone know what could be causing the following RUN TIME error in my Java
With the below code, nothing appears in the ListActivity as I would expect. No
This logic is written in a function with signature private void showDialog(final AdapterView<? extends
I have the following: <html> <script type=text/javascript> document.onmousemove = getCursorXY; function getCursorXY(e) { document.getElementById('cursorX').value
I'm getting some very jerky scrolling while using the code below to create a
I have: <script type=text/javascript> $(function() { var id = '<%=txtEditor.ClientID%>'; var editor = CodeMirror.fromTextArea(document.getElementById(id),
Is there a way to write the following function so that my IDE doesn't
SOLVED BELOW See below for solution I have a ListView with a custom adapter
I am calling the function EnumProcessModulesEx and it fails. I running on a 64-bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.