Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to delete x data sets from YDN Database and do something after that (async)?

I want to delete x rows from a YDN Database and after (!) this is done, do something else.

How can I make the "something else" wait for the delete-loop to finish?

I tried several options like

function DeleteAndThenDoSomethingElse()
{
    return new Promise((resolve, reject) => {

        var df = db.values('myDatabaseTable');
            
        df.done(function (items) {
            var n = items.length;
            var sequence = Promise.resolve();
            for (var i = 0; i < n; i++) 
            {
                const my_i = i;
                const my_premid = items[i].premid;
    
                console.log(i + ': delete Data-ID: '+ my_premid);
                sequence = sequence.then(async function() {
                    await db.remove('datenbank_id', my_premid).done(function() {
                        console.log('Delete of ' + my_premid + ' success.');    
                    }).fail(function(e) {
                        console.log(e.message);
                    });
                });
            }
            sequence = sequence.then(console.log('Now do something else'));
            return sequence;
        }   
    });
}

But the "Now do something else" never waits for the amount of "delete of XY success." I also tried without the async/await-addition. It seems that the db.remove always stays sync.

What do I have to change so that the deletions in the loop are executed first and then something that I chain to the promise after the loop?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda