Queue execution of promise function

//Promise
function app(num,data){
 
}

if you want to execute yourself again after a successful call

var data=[...]
//data.length=3
app(0)
.then(function(res){
    console.log(res)
    return app(1)
})
.then(function(res){
     console.log(res)
    return app(2)
});

if the number of times of execution is not sure how to implement it, it has been executed for 3 times, and the length of the returned data data is uncertain.

Mar.09,2021

if you are not connected to each other every time you execute app (), you can put it in an array and use Promise.all to execute

.
function app(num, data) {
    return new Promise(function (resolve, reject) {
        resolve(num)
    })
}

function test(arr, cb) {
    return arr.reduce((p, v) => p.then(() => cb(v)), Promise.resolve())
}

test([4, 1, 9], function (num) {
    return app(num).then(res => {
        console.log(res)
    });
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36d97-2c02b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36d97-2c02b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?