I have a array which I have to loop through. I can't use for loop because it's asynchronous and it has callback in. I would have to use a loop which waits for callback. Is that possible?
Code:
        if ( bots[1].getInventory().getItems().length < capacity ){  
            var executed = false;
            bots[1].createDeposit({
                steamid: req.query.steamid,
                token: req.query.token,
                itemsFromThem: uniqueItems,
                message: req.query.message,
                callback: function( err, dbTradeId ){
                    if ( !executed ){
                        executed = true;
                        if ( !err && dbTradeId ){
                            res.json({ result: 1, dbTradeId: dbTradeId });
                        } else {
                            console.log('» Tried to create deposit, but',err);
                            myMessages.push("Problem");
                            res.json({ error: err });                   
                        }
                    }
                }
            });
        } else {
            console.log('» Tried to create deposit, but no bot found(2)');
            myMessages.push("Available bot not found(2)");
        }
My question is not a duplicate because, I don't want it to go through every item in the array. Only until the successful callback has been executed.
Regards
 
     
    