Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Waiting for Async Request to finalize before doing something in javascript

I am working on a web app that uses Indexed DB to work. I want to check if an object with that ID exists in my Database. This is my actual code:

function checkKeyExists(id){
    request = window.indexedDB.open("ManagementDB", 1);
    let exists = false;
    request.onerror = function (event) {
        window.alert("Error using indexedDB");
        return false
    }
    request.onsuccess = function (event) {
        let getRequest = request.result.transaction("KeyStorage", "readonly").objectStore("KeyStorage").get(id)
        getRequest.onerror = function(event){
            console.log("Info: checkKey: error reading key "+ id+ " : " + event);
        }
        getRequest.onsuccess = function(event){
            if (typeof(getRequest.result) === 'object'){
                keyStatus = true;
            }
        }
    }
    
    // Need to wait for everything to finish before doing the return 
    return keyStatus
}

I do not know how to wait for all of the code to finish before executing the return. I am still a starter in javascript, it might be an easy question, but I did not get any response to this looking at other questions. Other questions uses await, but that would not resolve anything for me.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda